给出房子,障碍物,街道,都用一条线段表示,障碍物会遮挡房子
问在街道上可以完整看到房子的最大连续长度是多少
对于每个障碍物,可以在街道上求出遮挡房子的区域起点和终点
把这些点都保存下来,起点标记为-1,终点标记为1
另外把街道起点和终点保存下来,起点标记为1,终点标记为-1
然后按照x从小到大排序,遍历这些点,初始化f=0,每次到一个点f+=标记
可以发现f>0时,就代表接下来的这段区域可以完整看到房子,统计这些区域的最大值
注意障碍物可能不在房子和街道之间,这些障碍物就忽略不计
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=1000+10;
//Point定义
const double eps=1e-8;
const double PI=acos(-1.0);
int sgn(double x)
{
if(fabs(x)<eps) return 0;
if(x<0) return -1;
else return 1;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x=_x;y=_y;
}
Point operator - (const Point &b) const
{
return Point(x-b.x,y-b.y);
}
//叉积
double operator ^ (const Point &b) const
{
return x*b.y-y*b.x;
}
//点积
double operator * (const Point &b) const
{
return x*b.x+y*b.y;
}
///绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx=x,ty=y;
x=tx*cos(B)-ty*sin(B);
y=tx*sin(B)+ty*cos(B);
}
};
//两点描述直线
struct Line
{
Point s,e;
Line(){}
Line(Point _s,Point _e) { s = _s;e = _e; }
//两直线相交求交点
//第一个值为0表示直线重合,为1表示平行,为0表示相交,为2是相交
//只有第一个值为2时,交点才有意义
pair<int,Point> operator &(const Line &b)const
{
Point res = s;
if(sgn((s-e)^(b.s-b.e)) == 0)
{
if(sgn((s-b.e)^(b.s-b.e)) == 0)
return make_pair(0,res);//重合
else return make_pair(1,res);//平行
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x-s.x)*t;
res.y += (e.y-s.y)*t;
return make_pair(2,res);
}
}hou,pl,ob;
//两点间距离
double dist(Point a,Point b){return sqrt((a-b)*(a-b)); }
struct node
{
double x;
int f;
node(){}
node(double a,int b)
{
x=a;f=b;
}
bool operator < (const node &u) const
{
return x<u.x;
}
}z[N];
int main()
{
int n;
double a,b,c;
while(~scanf("%lf%lf%lf",&a,&b,&c))
{
if(a<eps&&b<eps&&c<eps) break;
hou.s.x=a;hou.e.x=b;hou.s.y=hou.e.y=c;
scanf("%lf%lf%lf",&a,&b,&c);
pl.s.x=a;pl.e.x=b;pl.s.y=pl.e.y=c;
int cnt=0;
z[cnt++]=node(pl.s.x,1);
z[cnt++]=node(pl.e.x,-1);
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf%lf",&a,&b,&c);
ob.s.x=a;ob.e.x=b;ob.s.y=ob.e.y=c;
if(sgn(c-hou.s.y)!=-1||sgn(c-pl.s.y)!=1) continue;
Point p=(Line(hou.e,ob.s)&pl).second;
z[cnt++]=node(p.x,-1);
p=(Line(hou.s,ob.e)&pl).second;
z[cnt++]=node(p.x,1);
}
sort(z,z+cnt);
double ans=0.0,t=0.0;
int f=z[0].f;
for(int i=1;i<cnt;i++)
{
if(f>0) t+=z[i].x-z[i-1].x;
else t=0.0;
f+=z[i].f;
ans=max(ans,t);
}
if(ans>=eps) printf("%.2f\n",ans);
else printf("No View\n");
}
return 0;
}