Video Surveillance POJ - 1474
2017-09-27 20:01
204 查看
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.
半平面交
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.
半平面交
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> using namespace std; #define eps 1e-8 const int MAXN=10010; int n; double r; int cCnt,curCnt; struct point{ double x,y; }; point points[MAXN],p[MAXN],q[MAXN]; void getline(point x,point y, double &a, double &b, double &c){ a=y.y-x.y; b=x.x-y.x; c=y.x*x.y-x.x*y.y; } void initial(){ for (int i=1;i<=n;i++) p[i]=points[i]; p[n+1]=p[1]; p[0]=p ; cCnt=n; } point intersect(point x,point y,double a,double b,double c){ double u=fabs(a*x.x+b*x.y+c); double v=fabs(a*y.x+b*y.y+c); point pt; pt.x=(x.x*v+y.x*u)/(u+v); pt.y=(x.y*v+y.y*u)/(u+v); return pt; } void cut(double a,double b,double c){ curCnt=0; int i; for (i=1;i<=cCnt;i++){ if (a*p[i].x+b*p[i].y+c>=0) q[++curCnt]=p[i]; else{ if (a*p[i-1].x+b*p[i-1].y+c>0){ q[++curCnt]=intersect(p[i],p[i-1],a,b,c); } if (a*p[i+1].x+b*p[i+1].y+c>0){ q[++curCnt]=intersect(p[i],p[i+1],a,b,c); } } } for (i=1;i<=curCnt;i++) p[i]=q[i]; p[curCnt+1]=q[1]; p[0]=p[curCnt]; cCnt=curCnt; } void solve(){ initial(); for (int i=1;i<=n;i++){ double a,b,c; getline(points[i],points[i+1],a,b,c); cut(a,b,c); } } void zhuanhua(){ for (int i=1;i<(n+1)/2;i++){ swap(points[i],points[n-i]); } } int main(){ int tt=1; while(~scanf("%d",&n)&&n) { for (int i = 1; i <= n; i++) { scanf("%lf%lf", &points[i].x, &points[i].y); } //zhuanhua(); points[n + 1] = points[1]; solve(); printf("Floor #%d\n",tt++); if (cCnt < 1) { printf("Surveillance is impossible.\n"); } else { printf("Surveillan 4000 ce is possible.\n"); } printf("\n"); } return 0; }
相关文章推荐
- poj 1474 Video Surveillance
- poj 1474 Video Surveillance
- poj 1474 Video Surveillance 半平面交
- POJ3335 POJ3130 POJ1474 [半平面交]
- POJ 1474 || Video Surveillance(半平面交
- VSAM:视频监控系统 A System for Video Surveillance and Monitoring
- The OpenCV Video Surveillance / Blob Tracker Facility
- BSOJ1850:POJ1474摄像头 计算几何 半平面交
- [poj 1474]Video Surveillance[半平面交][多边形的核]
- poj 1474 半平面交求多边形的核
- poj 3335 && poj 3130 && poj 2451 && poj 1474(n(logn)求解半平面交)
- POJ 1474 Video Surveillance -
- POJ 1474 ZOJ 1248 HDU 1469 Video Surveillance 半平面交
- POJ 1474 半面相交
- VSAM:视频监控系统 A System for Video Surveillance and Monitoring
- 【论文】Efficient compressed sensing based object detection system for video surveillance application
- poj 1474 Video Surveillance(半平面交)
- ●poj 1474 Video Surveillance
- POJ 1474 半平面交
- poj 1474 Video Surveillance (半平面交)