poj 2074
来源:互联网 发布:阿里巴巴分销传淘宝 编辑:程序博客网 时间:2024/06/05 08:58
直线的交点,题目不是很难,但还是太粗心,其中有一步疏忽,导致无限wa,最后还是发现了
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;const int maxn=10000;double eps=1e-10;struct node{double x1,x2,y;};struct Point {double x,y;Point(double x=0,double y=0):x(x),y(y) {};};node arc[maxn],hou,line;int n;struct node2{double l1,l2;};node2 ran[maxn];double max(double a,double b) { return a>b?a:b; }double cross(double x1,double y1,double x2,double y2){return x1*y2-y1*x2;}double getIn(Point a,Point b){double vx=b.x-a.x,vy=b.y-a.y;double wx=line.x2-line.x1,wy=0;double ux=a.x-line.x1,uy=a.y-line.y;double t=cross(wx,wy,ux,uy)/cross(vx,vy,wx,wy);return a.x+t*vx;}bool cmp(node2 a,node2 b){return a.l1<b.l1;}double solve(){int i;int tot=0;for(i=0;i<n;i++){if(!(arc[i].y>hou.y||arc[i].y<line.y)){double l1=getIn(Point(hou.x1,hou.y),Point(arc[i].x2,arc[i].y)), l2=getIn(Point(hou.x2,hou.y),Point(arc[i].x1,arc[i].y));if(l1<line.x1) l1=line.x1;if(l1>line.x2) l1=line.x2;if(l2<line.x1) l2=line.x1;if(l2>line.x2) l2=line.x2;ran[tot].l1=l2;ran[tot].l2=l1;tot++;}}sort(ran,ran+tot,cmp);double maxv=0;if(tot==0) return line.x2-line.x1;//思维不够严密,居然拉了这步,居然想了4个小时if(ran[0].l1>line.x1) maxv=ran[0].l1-line.x1;double tem=ran[0].l2;for(i=1;i<tot;i++){if(ran[i].l1>tem){maxv=max(maxv,ran[i].l1-tem);tem=ran[i].l2;}else tem=max(tem,ran[i].l2);}maxv=max(maxv,line.x2-ran[tot-1].l2);return maxv;}int main(){while(scanf("%lf%lf%lf",&hou.x1,&hou.x2,&hou.y)){if(hou.x1==0&&hou.x2==0&&hou.y==0) break;scanf("%lf%lf%lf",&line.x1,&line.x2,&line.y);int i;scanf("%d",&n);for(i=0;i<n;i++) scanf("%lf%lf%lf",&arc[i].x1,&arc[i].x2,&arc[i].y);double ans=solve();if(ans==0) printf("No View\n"); else printf("%.2lf\n",ans);}return 0;}
- POJ 2074
- poj 2074
- poj 2074
- poj 2074
- POJ 2074 视线问题
- POJ 2074 直线相交
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- SQL Server 2005数据表导出到Oracle的方案 .
- error C2668: “pow”: 对重载函数的调用不明确
- 成绩处理(结构体应用)
- 读:程序员成长路线图.后感
- 向LINUX内核添加驱动
- poj 2074
- 在Eclipse+ADT中开发Android系统的内置应用
- cocos2d-x系列笔记(5)---小精灵,走你!
- glib库hash表GHashTable介绍 .
- ios 多线程加载图片,并实现缓存
- php通过simplexml获取xml文件
- mysql索引
- 11级_Java_曹建波 03.06 Struts2_ognl
- Java之美[从菜鸟到高手演变]之Linux篇——Linux下增加swap分区的方法