poj 2074 Line of Sight
来源:互联网 发布:电脑声控软件 编辑:程序博客网 时间:2024/05/16 23:02
有一个trick就是如果house和 property line之间没有障碍物直接输出property line的长度即可
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>using namespace std;struct P{ double x,y; 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;};Line H,p;Line qs[100000],jiaodian[100000],jiaodian1[100000];bool judge(P a,P b,P c,P d){ if((c-a).det(b-a)*(d-a).det(b-a)<=0) return 1; return 0;}P in(P a,P b,P c,P d){ return c+(d-c)*((b-a).det(a-c) / (b-a).det(d-c));}double dis(P a,P b){ double c=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); return sqrt(c);}bool cmp(Line a,Line b){ if(a.a.x!=b.a.x) return a.a.x<b.a.x; return a.b.x<b.b.x;}bool cmp1(Line a,Line b){return a.b.x<b.b.x;}int main(){ double x1,x2,y1; while(~scanf("%lf%lf%lf",&x1,&x2,&y1)) {int i; if(x1==0 && x2==0 && y1==0) break; H.a.x=x1;H.a.y=y1; H.b.x=x2;H.b.y=y1; scanf("%lf%lf%lf",&p.a.x,&p.b.x,&p.a.y); p.b.y=p.a.y; int k,l=0,l1=0,l2=0; scanf("%d",&k); while(k--) { scanf("%lf%lf%lf",&x1,&x2,&y1);if(x1>p.b.x || x2<p.a.x)continue; if(y1>min(H.a.y,p.a.y) && y1<max(H.a.y,p.a.y)) { qs[l].a.x=x1; qs[l].b.x=x2; qs[l].a.y=qs[l].b.y=y1; l++; } }if(l==0){printf("%.2lf\n",p.b.x-p.a.x);continue;} for( i=0;i<l;i++) {P lf,rg;lf=in(H.b,qs[i].a,p.a,p.b);rg=in(H.a,qs[i].b,p.a,p.b); if(judge(H.b,qs[i].a,p.a,p.b)) jiaodian[l1].a=in(H.b,qs[i].a,p.a,p.b); else {jiaodian[l1].a.x=p.a.x;jiaodian[l1].a.y=p.a.y;} if(judge(H.a,qs[i].b,p.a,p.b)) jiaodian[l1].b=in(H.a,qs[i].b,p.a,p.b); else {jiaodian[l1].b.x=p.b.x;jiaodian[l1].b.y=p.b.y;} l1++;if(lf.x>p.b.x || rg.x<p.a.x)l1--;//printf("%lf %lf\n",jiaodian[l1-1].a.x,jiaodian[l1-1].b.x); }for(i=0;i<l1;i++){int fg=1;for(int j=0;j<l1;j++){if(i==j)continue;if(jiaodian[i].a.x>=jiaodian[j].a.x && jiaodian[i].b.x<=jiaodian[j].b.x)fg=0;}if(fg)jiaodian1[l2++]=jiaodian[i];} sort(jiaodian1,jiaodian1+l2,cmp); double ans=dis(p.a,jiaodian1[0].a); for( i=0;i<l2-1;i++) { int fg=1; Line hehe; hehe.a.x=0x7ffffff;//printf("%lf %lf\n",jiaodian1[i].a.x,jiaodian1[i].b.x); for(int j=i+1;j<l2;j++) { if(jiaodian1[j].a.x<=jiaodian1[i].b.x) fg=0; else { if(jiaodian1[j].a.x<hehe.a.x) hehe=jiaodian1[j]; } } if(fg) { double ans1=dis(jiaodian1[i].b,hehe.a); if(ans1>ans) ans=ans1; } }sort(jiaodian1,jiaodian1+l2,cmp1); double llll=dis(jiaodian1[l2-1].b,p.b); if(llll>ans) ans=llll; if(ans!=0) printf("%.2lf\n",ans); else printf("No View\n"); } return 0;}
0 0
- POJ 2074 Line of Sight
- poj 2074 Line of Sight
- Poj 2074 Line of Sight
- POJ 2074 Line of Sight
- POJ 2074 Line of Sight
- poj 2074 Line of Sight
- POJ 2074 Line of Sight
- poj 2074Line of Sight
- poj 2074 Line of Sight
- POJ 2074 Line of Sight(求交点)
- POJ 2074 Line of Sight 直线交
- Line of Sight - POJ 2074 直线交点
- POJ 2074 Line of Sight <几何>
- POJ 2074 Line of Sight(判线段与直线相交)
- poj 2074 Line of Sight(计算几何)
- POJ 2074 Line of Sight 直线相交+线段覆盖
- poj2074 Line of Sight
- Poj.2074 Line of Sight【计算几何-线段】 2015/08/28
- JQuery Mobile 的 Error Loading Page 问题
- C语言逗号表达式
- 一个应用启动另一个应用
- linux下杀死进程(kill)的N种方法
- cocos2dx备忘录(1)——在win7下创建一个win32项目并分别在win32和android平台下运行
- poj 2074 Line of Sight
- 项目优化经验分享(四)需求与原型图
- 基于Apache FTP点断续传的文件上传和下载
- 在 Redhat6.2 上安装 Oracle 11gR2 -- VMware + ASM
- C语言宏的高级用法
- c/c++面试题汇总(2)
- icanhazip.com 使你在任何地方知道你的公网IP地址
- 为程序员开一剂提高职业素养的良方
- C#与SQL命令中单引号字符串的不同效果