poj2074 Line of Sight【计算几何】
来源:互联网 发布:单位网络监控 编辑:程序博客网 时间:2024/06/11 16:54
题目大意:
题意:给出一个房子(看成线段)的端点坐标,和一条观光区的两端坐标,给出一些障碍物(看成线段)的两端坐标(都平行于x轴)。问在路上能看到完整房子的最大连续长度是多长。
【注意】
1. 输入的线段(x1,x2,y)保证x1
2. 输入的home一定在观光区上面
3. 输入的障碍物不一定在home和观光区之间
4. 如果输入的障碍物与home同y轴,不管重合与部分重合还是不重合,不算遮住。
5. 如果输入的障碍物与观光区重合,同理。
解题思路:
求出每个障碍在观光区上所阻挡的视野区间,然后去掉被覆盖的小区间求相邻两个区间之间的间隙最大值即可。
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<ctime>#include<vector>#include<queue>#define ll long longusing namespace std;int getint(){ int i=0,f=1;char c; for(c=getchar();(c!='-')&&(c<'0'||c>'9');c=getchar()); if(c=='-')c=getchar(),f=-1; for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0'; return i*f;}const int N=1005;const double eps=1e-8;int n;double ans;struct node{ double x1,x2,y; inline friend bool operator <(const node &a,const node &b) { if(a.x1==b.x1)return a.x2>b.x2; return a.x1<b.x1; }}a[N],h,p;double calc(double x1,double y,double x2){ if(fabs(x1-x2)<eps)return x1; double k=(h.y-y)*1.0/(x2-x1); double m=y-k*x1; double res=(p.y-m)*1.0/k; return res;}int main(){ //freopen("lx.in","r",stdin); double x1,x2,y; while(scanf("%lf%lf%lf",&h.x1,&h.x2,&h.y)) { if(!h.x1&&!h.x2&&!h.y)break; ans=0; scanf("%lf%lf%lf",&p.x1,&p.x2,&p.y); n=getint(); for(int i=1;i<=n;i++) { scanf("%lf%lf%lf",&x1,&x2,&y); if(y>=h.y||y<=p.y) { i--,n--; continue; } a[i].x1=calc(x1,y,h.x2); a[i].x2=calc(x2,y,h.x1); } ++n,a[n].x1=a[n].x2=p.x1; ++n,a[n].x1=a[n].x2=p.x2; sort(a+1,a+n+1); int top=1; for(int i=2;i<=n;i++) if(a[i].x2>a[top].x2)a[++top]=a[i]; n=top; int i=1; while(a[i].x2<p.x1)i++; for(i;i<n;i++)ans=max(ans,a[i+1].x1-a[i].x2); if(!ans)puts("No View"); else printf("%0.2f\n",ans); } return 0;}
阅读全文
0 0
- poj2074 Line of Sight【计算几何】
- poj2074 Line of Sight
- poj 2704 Line of Sight(数学型计算几何)
- poj 2074 Line of Sight(计算几何)
- POJ 2074 Line of Sight <几何>
- Poj.2074 Line of Sight【计算几何-线段】 2015/08/28
- 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
- Navigation Mesh与Line-of-Sight Test
- Navigation Mesh与Line-of-Sight Test
- POJ 2074 Line of Sight(求交点)
- MySQL的if,case语句使用总结
- Java类加载的过程
- 深度优先搜索:杭电1045
- VS2017编写汇编并调用c库函数(msvcrt.lib)
- 海量数据处理十个方法大总结
- poj2074 Line of Sight【计算几何】
- 多线程及线程池
- 引用类型-Array-创建
- Fibonacci again and again (SG值运用)
- Blog21@linux介绍Apahe
- 树上最长上升子序列
- leetCode-Degree of an Array
- 写冒泡排序可以排序多个字符串.
- nginx编写http模块编译报错