传送门
直接暴力
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;
}
本文介绍了如何解决bzoj4614题目中的Oil问题,采用暴力枚举结合斜率排序的方法,实现了O(n^2 log n)的时间复杂度。在实际运行中发现数据与题意存在不匹配的情况,导致了一些调试挑战。
&spm=1001.2101.3001.5002&articleId=98105419&d=1&t=3&u=2fb3615989b74afc8760a4d39ff7b044)
772

被折叠的 条评论
为什么被折叠?



