POJ 1474 Video Surveillance (半平面交判断)
2015-12-14 22:19
323 查看
Video Surveillance
Description
A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- ment store. One of his tasks is to install a video surveillance system to guarantee the security of the customers (and the security
of the merchandise of course) on all of the store's countless floors. As the company has only a limited budget, there will be only one camera on every floor. But these cameras may turn around to look in every direction.
The first problem is to choose where to install the camera for every floor. The only requirement is that every part of the room must be visible from there. In the following figure the left floor can be completely surveyed from the position indicated by a dot,
while for the right floor, there is no such position, the given position failing to see the lower left part of the floor.
Before trying to install the cameras, your friend first wants to know whether there is indeed a suitable position for them. He therefore asks you to write a program that, given a ground plan, de- termines whether there is a position from which the whole floor
is visible. All floor ground plans form rectangular polygons, whose edges do not intersect each other and touch each other only at the corners.
Input
The input contains several floor descriptions. Every description starts with the number n of vertices that bound the floor (4 <= n <= 100). The next n lines contain two integers each, the x and y coordinates for the n vertices,
given in clockwise order. All vertices will be distinct and at corners of the polygon. Thus the edges alternate between horizontal and vertical.
A zero value for n indicates the end of the input.
Output
For every test case first output a line with the number of the floor, as shown in the sample output. Then print a line stating "Surveillance is possible." if there exists a position from which the entire floor can be observed,
or print "Surveillance is impossible." if there is no such position.
Print a blank line after each test case.
Sample Input
Sample Output
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3612 | Accepted: 1617 |
A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- ment store. One of his tasks is to install a video surveillance system to guarantee the security of the customers (and the security
of the merchandise of course) on all of the store's countless floors. As the company has only a limited budget, there will be only one camera on every floor. But these cameras may turn around to look in every direction.
The first problem is to choose where to install the camera for every floor. The only requirement is that every part of the room must be visible from there. In the following figure the left floor can be completely surveyed from the position indicated by a dot,
while for the right floor, there is no such position, the given position failing to see the lower left part of the floor.
Before trying to install the cameras, your friend first wants to know whether there is indeed a suitable position for them. He therefore asks you to write a program that, given a ground plan, de- termines whether there is a position from which the whole floor
is visible. All floor ground plans form rectangular polygons, whose edges do not intersect each other and touch each other only at the corners.
Input
The input contains several floor descriptions. Every description starts with the number n of vertices that bound the floor (4 <= n <= 100). The next n lines contain two integers each, the x and y coordinates for the n vertices,
given in clockwise order. All vertices will be distinct and at corners of the polygon. Thus the edges alternate between horizontal and vertical.
A zero value for n indicates the end of the input.
Output
For every test case first output a line with the number of the floor, as shown in the sample output. Then print a line stating "Surveillance is possible." if there exists a position from which the entire floor can be observed,
or print "Surveillance is impossible." if there is no such position.
Print a blank line after each test case.
Sample Input
4 0 0 0 1 1 1 1 0 8 0 0 0 2 1 2 1 1 2 1 2 2 3 2 3 0 0
Sample Output
Floor #1 Surveillance is possible. Floor #2 Surveillance is impossible. ac代码:
#include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<queue> #include<vector> #include<iostream> #include<algorithm> #define MAXN 60001 #define LL long long #define INF 0xfffffff #define mem(aa) memset(aa,0,sizeof(aa)) #define PI acos(-1) #define eps 1e-8 using namespace std; struct s { double x,y; }; s list[MAXN],p[MAXN],q[MAXN]; double a,b,c; int cnt,ccnt,n; void getline(s x,s y) { a=y.y-x.y;b=x.x-y.x;c=y.x*x.y-x.x*y.y; } s xlist(s x,s y) { double u=fabs(a*x.x+b*x.y+c); double v=fabs(a*y.x+b*y.y+c); s k; k.x=(x.x*v+y.x*u)/(u+v); k.y=(x.y*v+y.y*u)/(u+v); return k; } void cut() { ccnt=0; for(int i=1;i<=cnt;i++) { if(a*p[i].x+b*p[i].y+c>=0) q[++ccnt]=p[i]; else { if(a*p[i-1].x+b*p[i-1].y+c>0) q[++ccnt]=xlist(p[i],p[i-1]); if(a*p[i+1].x+b*p[i+1].y+c>0) q[++ccnt]=xlist(p[i],p[i+1]); } } for(int i=1;i<=ccnt;i++) p[i]=q[i]; p[ccnt+1]=q[1];p[0]=p[ccnt]; cnt=ccnt; } void solve() { int i; for(i=1;i<=n;i++) p[i]=list[i]; p[n+1]=p[1];p[0]=p ; cnt=n; for(i=1;i<=n;i++) { getline(list[i],list[i+1]); cut(); } } int main() { int t,i; int cas=0; while(scanf("%d",&n)!=EOF,n) { for(i=1;i<=n;i++) scanf("%lf%lf",&list[i].x,&list[i].y); list[n+1]=list[1]; solve(); printf("Floor #%d\n",++cas); if(cnt>0) printf("Surveillance is possible.\n"); else printf("Surveillance is impossible.\n"); printf("\n"); } return 0; }
相关文章推荐
- 总结:数据库连接字符串的使用方法
- iOS开发之UICollectionView
- 项目开发技巧之开发文档建立
- project euler 82
- 使用GestureOverlayView控件实现手势识别
- Java多线程总结(2) — 线程生命周期中常用方法
- Struts2的输入验证
- Struts2的输入验证
- 集群-基础知识3
- 大话设计模式 笔记1——简单工厂模式
- 《java多线程编程核心技术》之Timer
- cuda core和sp
- 4-3 简单求和
- Android Studio 常用快捷键
- 56.多线程第三章(重点)
- iOS开发之”人机界面准则“
- 数字和字符串的转换
- Linux之内存泄露的检测工具
- Linux环境PHP7.0安装
- 企业版证书 打包 发布(网站) 流程