一开始想复杂了 想到网络流去了
一定有一条卡住两个端点的直线是最优解。所以枚举一个端点,以它为极坐标原点后其他每个线段覆盖了一个角度区间。
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
inline char nc()
{
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x)
{
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
inline int dcmp(double a,double b){
if (fabs(a-b)<1e-12) return 0;
if (a<b) return -1; return 1;
}
const int N=2005;
struct Point{
int x,y;
friend double K(Point p1,Point p0){
if (p1.x==p0.x) return 1e130;
return (double)(p1.y-p0.y)/(p1.x-p0.x);
}
Point(int x=0,int y=0):x(x),y(y) { }
void read(){
::read(x),::read(y);
}
}P[N][2],now;
int n,ans;
inline bool cmp(double t1,double t2){
if (t1*t2>0) return t1>t2;
return t1<0;
}
struct abcd{
double t; int f;
bool operator < (const abcd &B) const{
if (dcmp(t,B.t)==0) return f>B.f;
return cmp(t,B.t);
}
abcd(double t=0,int f=0):t(t),f(f) { }
}eve[N<<1];
int tot;
inline void Solve(int u,int v){
now=P[u][v];
int ret=0,tem=0; double k1,k2;
tot=0;
for (int i=1;i<=n;i++)
{
if (P[i][0].y==P[u][0].y) continue;
k1=K(P[i][0],now);
k2=K(P[i][1],now);
if (!cmp(k1,k2)) swap(k1,k2);
eve[++tot]=abcd(k1,P[i][1].x-P[i][0].x);
eve[++tot]=abcd(k2,P[i][0].x-P[i][1].x);
}
sort(eve+1,eve+tot+1);
for (int i=1;i<=tot;i++)
{
tem+=eve[i].f;
ret=max(ret,tem);
}
if (ret+P[u][1].x-P[u][0].x>ans)
ans=ret+P[u][1].x-P[u][0].x;
}
int main()
{
int ix1,ix2,iy;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
read(n);
for (int i=1;i<=n;i++)
{
read(ix1),read(ix2),read(iy);
if (ix1>ix2) swap(ix1,ix2);
P[i][0]=Point(ix1,iy),P[i][1]=Point(ix2,iy);
}
for (int i=1;i<=n;i++)
Solve(i,0),Solve(i,1);
printf("%d\n",ans);
return 0;
}