poj 1039 Pipe
来源:互联网 发布:重做系统c盘数据恢复 编辑:程序博客网 时间:2024/04/30 20:01
题意:给定一个管道,要求判断射入管道的光线能达到的最远x坐标;
思路:枚举上下管道的点,一个上管道点,一个下管道点
不好处理的是光线与线段不规范相交的情况
首先要判断光线与每个点竖线是否相交,从而判断光线是否在管道内部
然后有这样一种情况,就是最后的交点是线段的端点。。。这让我WA了很久。。主要是没处理到这种情况。。后来看到了
一组数据才恍然大悟4
0 1
1 2
2 1
3 -1
妈蛋。。。。。WA了好久
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define inf 0x7ffffffusing namespace std;const double eps=1e-3;const double pi=acos(-1.0);struct P{ double x,y;int index; P () {} P (double x,double y):x(x),y(y){ } P operator -(P p){ return P(x-p.x,y-p.y); } P operator +(P p){ return P(x+p.x,y+p.y); } P operator *(double d){ return P(x*d,y*d); } double det(P p){ return x*p.y-y*p.x; }};struct Line{ P a,b;};P p[100000],q[1000000],q1[1000000];int l1,l2;Line qs[100000],ps[100000];int n,k;double mnx;int judge1(Line l,P a,P b){ if((l.a-a).det(b-a)*(l.b-a).det(b-a)<0) //规范相交 return 1; if((l.a-a).det(b-a)*(l.b-a).det(b-a)==0)//不规范相交 return -1; return 0;}bool judge2(P a,P b,int i){if((p[i]-a).det(b-a)*(p[i+n]-a).det(b-a)<=0) return 1; return 0;}P in(Line l,P a,P b){ return l.a+(l.b-l.a)*((b-a).det(a-l.a) / (b-a).det(l.b-l.a));}int fg;double judge(P a,P b){ double ans=inf*1.0;int i;double ax; for( i=0;i<k;i++) {P r;if(!judge2(a,b,qs[i].a.index))break;if(judge1(qs[i],a,b)==1) {r=in(qs[i],a,b);if(r.x<ans)ans=r.x;}else if(judge1(qs[i],a,b)==-1){ ax=qs[i].a.x;}if(judge1(ps[i],a,b)==1){r=in(ps[i],a,b);if(r.x<ans)ans=r.x;}else if(judge1(ps[i],a,b)==-1){ ax=ps[i].a.x;} }if(i==k && !judge2(a,b,qs[k-1].b.index) && ans==inf*1.0)ans=ax; if(ans!=inf*1.0) return ans; else { if(i==k)fg=1;return -ans; }}int main(){ while(~scanf("%d",&n) && n!=0) {int ll=0;int i;l1=l2=0; k=0;fg=0; mnx=-inf*1.0; for( i=0;i<n;i++) { scanf("%lf%lf",&p[i].x,&p[i].y);p[i].index=i; p[i+n]=p[i]; p[i+n].y--; } for( i=0;i<n-1;i++) {qs[k].a=p[i];qs[k++].b=p[i+1];} for( i=n;i<2*n-1;i++) {ps[ll].a=p[i];ps[ll++].b=p[i+1];} for( i=0;i<n;i++) { for(int j=n;j<2*n-1;j++) { double aaa=judge(p[i],p[j]); if(aaa>mnx) mnx=aaa; } } if(fg) printf("Through all the pipe.\n"); else printf("%.2lf\n",mnx); } return 0;}
0 0
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- poj 1039 Pipe
- POJ 1039 pipe
- POJ 1039--Pipe
- poj 1039 Pipe
- Pipe - POJ 1039 几何
- POJ 1039 Pipe
- poj 1039 Pipe
- POJ-1039-Pipe
- POJ 1039 Pipe
- poj 1039 Pipe
- vc6转vs2010错误改正总结
- Red Hat Enterprise Linux 5下有关dmrc文件错误的解决办法
- IIS报错:未能加载文件或程序集"file:///c:/windows/temp/iuwelzdf.dll"或它的一个依赖项。系统找不到指定的文件
- FusionCharts使用教程:为图表添加向下钻取链接
- 链表
- poj 1039 Pipe
- git常用命令
- 一般动画
- mysql高级 存储过程[2] handler 的continue 和 exit 还有[undo]
- Android 模拟器一键获取root权限 一键安装Google play 服务
- android 像素处理
- 同学小智智的腾讯面试之行---心理测试过程很精彩真实
- Web_PHP_PHPsubstr截取中文字符出现乱码解决;
- 创建SvcHost.exe调用的服务原理与实践