poj1474Video Surveillance【半平面交判断内核是否存在】

来源:互联网 发布:端口 英文 编辑:程序博客网 时间:2024/06/14 09:48

Language:
Video Surveillance
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3555 Accepted: 1587

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

40 00 11 11 080 00 21 21 12 12 23 23 00

Sample Output

Floor #1Surveillance is possible.Floor #2Surveillance is impossible.

题意:求多边形内核是否存在

#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#define eps 1e-10using namespace std;struct point{double x,y;}A[110],p[110],q[110];int N,endcnt,tempcnt;void init(){for(int i=1;i<=N;++i){p[i]=A[i];}p[N+1]=p[1];p[0]=p[N];endcnt=N;}void getline(point p1,point p2,double &a,double &b,double &c){a=p2.y-p1.y;b=p1.x-p2.x;c=p2.x*p1.y-p2.y*p1.x;}point getinter(point p1,point p2,double a,double b,double c){double u=fabs(a*p1.x+b*p1.y+c);double v=fabs(a*p2.x+b*p2.y+c);point temp;temp.x=(p1.x*v+p2.x*u)/(u+v);temp.y=(p1.y*v+p2.y*u)/(u+v);return temp;}void cut(double a,double b,double c){tempcnt=0;for(int i=1;i<=endcnt;++i){if(a*p[i].x+b*p[i].y+c>=0)q[++tempcnt]=p[i];else {if(a*p[i-1].x+b*p[i-1].y+c>0){q[++tempcnt]=getinter(p[i],p[i-1],a,b,c);}if(a*p[i+1].x+b*p[i+1].y+c>0){q[++tempcnt]=getinter(p[i],p[i+1],a,b,c);}}}for(int i=1;i<=tempcnt;++i){p[i]=q[i];}p[tempcnt+1]=p[1];p[0]=p[tempcnt];endcnt=tempcnt;}void guizheng(){for(int i=1;i<=N;++i){q[i]=A[N-i+1];}for(int i=1;i<=N;++i){A[i]=q[i];}}void slove(){//guizheng();A[N+1]=A[1];init();for(int i=1;i<=N;++i){double a,b,c;getline(A[i],A[i+1],a,b,c);cut(a,b,c);}if(endcnt<=0)printf("Surveillance is impossible.\n");else printf("Surveillance is possible.\n");}int main(){int t=1,i;while(scanf("%d",&N),N){for(i=1;i<=N;++i){scanf("%lf%lf",&A[i].x,&A[i].y);}printf("Floor #%d\n",t++);slove();printf("\n");}return 0;}

0 0