bzoj4614: [Wf2016]Oil(暴力)

本文介绍了如何解决bzoj4614题目中的Oil问题,采用暴力枚举结合斜率排序的方法,实现了O(n^2 log n)的时间复杂度。在实际运行中发现数据与题意存在不匹配的情况,导致了一些调试挑战。

传送门
直接暴力 O ( n 2 log ⁡ n ) O(n^2\log n) O(n2logn)即可。
枚举每个点然后按斜率排序,就变成了一个 f o r for for循环问题。
注意数据与题意不符233333,因为这个调了很久,即不能用斜率为0的直线 NMD
代码:

#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
const int rlen=1<<18|1;
inline char gc(){
    static char buf[rlen],*ib,*ob;
    (ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin));
    return ib==ob?-1:*ib++;
}
inline int read(){
    int ans=0;
    bool f=1;
    char ch=gc();
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
    return f?ans:-ans;
}
typedef long long ll;
const int N=2005;
struct pt{
    int x,y;
    pt(int x=0,int y=0):x(x),y(y){}
    friend inline pt operator+(const pt&a,const pt&b){return pt(a.x+b.x,a.y+b.y);}
    friend inline pt operator-(const pt&a,const pt&b){return pt(a.x-b.x,a.y-b.y);}
    inline double slope()const{return (double)y/(double)x;}
};
typedef pair<pt,int> pii;
const double eps=1e-8;
inline int sgn(const double&x){return (x>eps)-(x<-eps);}
struct Node{
    double slp;int w;
    friend inline bool operator<(const Node&a,const Node&b){return sgn(a.slp-b.slp)?a.slp<b.slp:a.w>b.w;}
};
pii a[N<<1];
int n;
int main(){
    n=read();
    for(ri i=1,x1,x2,y;i<=n;++i){
        x1=read(),x2=read(),y=read();
        if(x1>x2)swap(x1,x2);
        a[i]=pii(pt(y,x1),x2-x1),a[i+n]=pii(pt(y,x2),x1-x2);
    }
    vector<Node>t;
    ll sum,ans=0;
    for(ri i=1;i<=n*2;++i){
        t.clear();
        for(ri j=1;j<=n*2;++j){
            if(a[i].fi.x==a[j].fi.x);
            else if(a[i].fi.x>a[j].fi.x)t.push_back((Node){(a[i].fi-a[j].fi).slope(),-a[j].se});
            else t.push_back((Node){(a[i].fi-a[j].fi).slope(),a[j].se});
        }
        ans=max(ans,sum=abs(a[i].se));
        sort(t.begin(),t.end());
        for(ri j=0,up=t.size();j<up;++j)sum+=t[j].w,ans=max(ans,sum);
    }
    cout<<ans;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值