题意:求路上的最长连续能看到房子的长度
真的蠢 半天没想到下面这两张图 看了一眼题解被自己蠢哭
面向discuss编程
漏算了起始区间 末尾区间 以及初始化问题 嗯 分别wa了一次
int main()
{
// freopen("in.txt","r",stdin);
Line house,road;
double x1,x2,y;
int n,k,m;
while(scanf("%lf%lf%lf",&x1,&x2,&y)!=EOF)
{
if(sgn(x1+x2+y)==0)break;
house=Line(Point(x1,y),Point(x2,y));
scanf("%lf%lf%lf",&x1,&x2,&y);
road=Line(Point(x1,y),Point(x2,y));
scanf("%d",&n);
k=0;
for(int i=0;i<n;i++)
{
scanf("%lf%lf%lf",&x1,&x2,&y);
if(sgn((y-house.s.y)*(y-road.s.y))>=0)continue;
ob[k++]=Line(Point(x1,y),Point(x2,y));
}
if(!k)
{
printf("%.2lf\n",road.e.x-road.s.x);
continue;
}
sort(ob,ob+k);
for(int i=0;i<k;i++)
{
Line t=Line(house.e,ob[i].s);
Point st=t&road;
t=Line(house.s,ob[i].e);
Point et=t&road;
broad[i]=Line(st,et);
}
sort(broad,broad+k);
double ans=0;
croad[0]=broad[0];
if(sgn(croad[0].s.x-road.s.x)>0)ans=croad[0].s.x-road.s.x;
m=1;
for(int i=1;i<k;i++)
{
if(sgn(broad[i].s.x-croad[m-1].e.x)<0)
{
croad[m-1].e.x=max(croad[m-1].e.x,broad[i].e.x);
}
else
{
croad[m++]=broad[i];
}
}
for(int i=1;i<m;i++)
{
ans=max(ans,croad[i].s.x-croad[i-1].e.x);
if(sgn(croad[i].e.x-road.e.x)>0)break;
}
if(sgn(croad[m-1].e.x-road.e.x)<0)ans=max(road.e.x-croad[m-1].e.x,ans);
if(sgn(ans)>0)
printf("%.2lf\n",ans);
else
printf("No View\n");
}
return 0;
}