poj 2074 Line of Sight
2015-08-17 18:00
411 查看
An architect is very proud of his new home and wants to be sure it can be seen by people passing by his property line along the street. The property contains various trees, shrubs, hedges, and other obstructions that may block the view. For the purpose of this
problem, model the house, property line, and obstructions as straight lines parallel to the x axis:
To satisfy the architect's need to know how visible the house is, you must write a program that accepts as input the locations of the house, property line, and surrounding obstructions and calculates the longest continuous portion of the property line from
which the entire house can be seen, with no part blocked by any obstruction.
Input
Because each object is a line, it is represented in the input file with a left and right x coordinate followed by a single y coordinate:
< x1 > < x2 > < y >
Where x1, x2, and y are non-negative real numbers. x1 < x2
An input file can describe the architecture and landscape of multiple houses. For each house, the first line will have the coordinates of the house. The second line will contain the coordinates of the property line. The third line will have a single integer
that represents the number of obstructions, and the following lines will have the coordinates of the obstructions, one per line.
Following the final house, a line "0 0 0" will end the file.
For each house, the house will be above the property line (house y > property line y). No obstruction will overlap with the house or property line, e.g. if obstacle y = house y, you are guaranteed the entire range obstacle[x1, x2] does not intersect with house[x1,
x2].
Output
For each house, your program should print a line containing the length of the longest continuous segment of the property line from which the entire house can be to a precision of 2 decimal places. If there is no section of the property line where the entire
house can be seen, print "No View".
Sample Input
Sample Output
给你一个上边和下边 然后给出档版 求出在下边连续最长能看到上边的最长长度
problem, model the house, property line, and obstructions as straight lines parallel to the x axis:
To satisfy the architect's need to know how visible the house is, you must write a program that accepts as input the locations of the house, property line, and surrounding obstructions and calculates the longest continuous portion of the property line from
which the entire house can be seen, with no part blocked by any obstruction.
Input
Because each object is a line, it is represented in the input file with a left and right x coordinate followed by a single y coordinate:
< x1 > < x2 > < y >
Where x1, x2, and y are non-negative real numbers. x1 < x2
An input file can describe the architecture and landscape of multiple houses. For each house, the first line will have the coordinates of the house. The second line will contain the coordinates of the property line. The third line will have a single integer
that represents the number of obstructions, and the following lines will have the coordinates of the obstructions, one per line.
Following the final house, a line "0 0 0" will end the file.
For each house, the house will be above the property line (house y > property line y). No obstruction will overlap with the house or property line, e.g. if obstacle y = house y, you are guaranteed the entire range obstacle[x1, x2] does not intersect with house[x1,
x2].
Output
For each house, your program should print a line containing the length of the longest continuous segment of the property line from which the entire house can be to a precision of 2 decimal places. If there is no section of the property line where the entire
house can be seen, print "No View".
Sample Input
2 6 6 0 15 0 3 1 2 1 3 4 1 12 13 1 1 5 5 0 10 0 1 0 15 1 0 0 0
Sample Output
8.80 No View
给你一个上边和下边 然后给出档版 求出在下边连续最长能看到上边的最长长度
#include <iostream> #include <math.h> #include <algorithm> using namespace std; int tot; struct LINESEG { double s,e,y; }; LINESEG l[1000],s[1000]; LINESEG h,p; void getx(LINESEG a,LINESEG b)//计算在道路上看不到的端点 { double temp; // s[tot].s=( (b.s*a.y-a.e*b.y)+ p.y*(a.e-b.s) )/ (a.y-b.y); // s[tot].e=( (b.e*a.y-a.s*b.y)+ p.y*(a.s-b.e) )/ (a.y-b.y); // printf("%lf %lf\n",s[tot].s,s[tot].e); s[tot].s=(a.e-b.s)*(p.y-b.y)/(a.y-b.y)+b.s; s[tot].e=(a.s-b.e)*(p.y-b.y)/(a.y-b.y)+b.e; s[tot].y=p.y; // printf("%lf %lf\n\n",s[tot].s,s[tot].e); if(s[tot].s>s[tot].e) { temp=s[tot].s; s[tot].s=s[tot].e; s[tot].e=temp; } tot++; } bool cmp(LINESEG a,LINESEG b) { if(a.s==b.s) return a.e<b.e; return a.s<b.s; } int main() { int i,n; while(~scanf("%lf%lf%lf",&h.s,&h.e,&h.y)) { tot=0; double r=-99999999,maxl=0; memset(s,0,sizeof(s)); if(h.s==0 && h.e==0 && h.y==0) break; scanf("%lf%lf%lf",&p.s,&p.e,&p.y); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%lf%lf%lf",&l[i].s,&l[i].e,&l[i].y); if(l[i].y>=h.y || l[i].y<p.y) continue; getx(h,l[i]); } sort(s,s+tot,cmp); r=s[0].e; if(s[0].s>p.s) { if(s[0].s<=p.e) maxl=max(maxl,s[0].s-p.s); else maxl=max(maxl,p.e-p.s); } for(i=1;i<n;i++) { if(s[i].s>r) { if(s[i].s>p.e) maxl=max(maxl,p.e-r); else maxl=max(maxl,s[i].s-r); r=s[i].e; } else if(s[i].e>r) r=s[i].e; } if(p.e>r) maxl=max(maxl,p.e-r); if(maxl<0.0000001) printf("No View\n"); else printf("%.2lf\n",maxl); } return 0; }
相关文章推荐
- 安装PHP
- 查找linux设备的uuid
- [转]curl_multi 实现准多进程发请求
- Android ActivityManager与WindowManager
- 查找linux设备的uuid
- 使用query参数过滤组合AWS CLI输出信息
- C++BuilderX8e Mysql存过程储过程的增、删、改
- js实现Select头像选择实时预览代码
- Android之断点续传(二)
- 继承映射关系 subclass的查询
- css3--断行问题+多余的字用省略号代替
- SparkStreaming找不到reduceByKey的解决方法
- python3.4多线程实现同步的四种方式
- hdoj 1260 Tickets【dp】
- wpf中,隐藏或去除window右上角的关闭按钮
- 生涯咨询中的点点感触
- Codeforces 138C(区间更新+离散化)
- QTP显示TestFlow
- HttpSessionListener进行同名用户剔除登录的方法
- UVALive 3211 Now or later || 2-sat + 二分