POJ 2074 Line of Sight(判线段与直线相交)
来源:互联网 发布:上虞区干部网络教育 编辑:程序博客网 时间:2024/05/16 19:34
题目大意:一栋漂亮的房子希望道路上的人可以看见,但是有一些障碍物在房子周围,无法透过障碍物看到房子。求可以在道路上看到房子的最大连续距离。
有这么两点要注意:障碍可能在房子后,与房子平行,或者在道路的另一侧。这些障碍都不用算的。
障碍可能在道路和房子外。(总之就是障碍可能在anywhere!)
所求的是最大连续距离。
//Memory: 216K//Time: 0MS#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);s[tot].y=p.y;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);elsemaxl=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);elsemaxl=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");elseprintf("%.2lf\n",maxl);}return 0;}
- POJ 2074 Line of Sight(判线段与直线相交)
- POJ 2074 Line of Sight 直线相交+线段覆盖
- poj 2074 Line of Sight(视线问题,求直线与线段的交点及判断相交)
- POJ 2074 Line of Sight 直线交
- Line of Sight - POJ 2074 直线交点
- POJ 3304 Segments(判线段与直线相交)
- 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 <几何>
- Poj.2074 Line of Sight【计算几何-线段】 2015/08/28
- Spring+JdbcDaoSupport
- 代码帝:一个月10万行代码 (只为存着膜拜)
- vc控制台编程1
- XP系统更改程序默认安装路径
- 一名大学毕业生的反思
- POJ 2074 Line of Sight(判线段与直线相交)
- 文件传输协议(File Transfer Protocol, FTP)(2)
- Ubuntu OS xen虚拟机上测试lvs和keepalived负载均衡
- 我的大学我做主
- poj 1080 最长公共子串变形
- .ftp
- Android利用ViewFlipper实现屏幕切换动画效果
- 武大校长的一封信
- 关于static函数的用法和全局变量在工程中的引用