可以想到一定是2个端点连成的线可以达到最远x距离,枚举两个端点就是了,不能跟端点前面的线相交,也不能通过端点超出管道的范围。最烦的是平时交到端点都算交,现在不算了,各种要改,而在端点处被挡住了又要算出这个端点。所以判断很麻烦
我感觉和别人的写的一个道理,discuss里各种数据都能过,然而就是WA,我是真的佛了
换成别人代码就过了这是为什么啊
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxl 25
#define eps 1e-8
const long long inf =1ll<<62;
inline int sgn(double x)
{
if(fabs(x)<eps) return 0;
if(x<0) return -1;
else return 1;
}
struct point
{
double x,y;
point(double a=0,double b=0)
{
x=a;y=b;
}
point operator + (const point &b)const
{
return point(x+b.x,y+b.y);
}
point operator - (const point &b)const
{
return point(x-b.x,y-b.y);
}
friend point operator * (const double &t,const point &p)
{
return point(t*p.x,t*p.y);
}
friend point operator * (const point &p,const double &t)
{
return point(t*p.x,t*p.y);
}
friend point operator / (const point &p,const double &t)
{
return point(p.x/t,p.y/t);
}
};
inline double det(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
}
inline double dot(const point &a,const point &b)
{
return a.x*b.x+a.y*b.y;
}
struct line
{
point s,e;
double k;
line(point a=point(),point b=point())
{
s=a;e=b;
k=atan2(e.y-s.y,e.x-s.x);
}
};
int n;
point a[maxl],b[maxl],C,D;
double len,ans;
inline void prework()
{
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
b[i]=point(a[i].x,a[i].y-1);
}
}
point getpos(point P,point v,point Q,point w){//两直线交点
point u=P-Q;
double t=det(w,u)/det(v,w);
return (P+(v*t));
}
inline bool check(point A,point B)
{
return (det(C-A,D-A)*det(C-B,D-B)<-eps);
}//规范相交
inline bool Across(point A,point B)
{
return (det(C-A,D-A)*det(C-B,D-B)<eps);
}//相交
inline bool sameside(point A,point B)
{
return (det(D-C,A-C)*det(D-C,B-C)>eps);
}//叉积判断在直线同侧
inline void mainwork()
{
bool flg=1;ans=-inf;
for(int i=1;i<=n&&flg;i++)
for(int j=1,k;j<=n;j++)
if(i!=j)
{
C=a[i],D=b[j];
for(k=1;k<n;k++)
if(check(a[k],a[k+1])||check(b[k],b[k+1])||sameside(a[k+1],b[k+1])||sameside(a[k],b[k]))
break;
if(k==n)
{
flg=0;
break;
}
if(k>=i&&k>=j){//真实直线
double tep_a=-inf,tep_b=-inf;
if(Across(a[k],a[k+1])) tep_a=getpos(a[k],a[k+1]-a[k],C,D-C).x;
if(Across(b[k],b[k+1])) tep_b=getpos(b[k],b[k+1]-b[k],C,D-C).x;
if(tep_a>ans) ans=tep_a;if(tep_b>ans) ans=tep_b;
}
}
if(!flg) ans=a[n].x+1;
}
inline void print()
{
if(ans>a[n].x+eps)
puts("Through all the pipe.");
else
printf("%.2f\n",ans);
}
int main()
{
while(~scanf("%d",&n) && n)
{
prework();
mainwork();
print();
}
return 0;
}