首页 > 代码库 > poj 1474 Video Surveillance (半平面交)
poj 1474 Video Surveillance (半平面交)
链接:http://poj.org/problem?id=1474
Video Surveillance
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3247 | Accepted: 1440 |
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.
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.
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.
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.
Source
Southwestern European Regional Contest 1997
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
测模板第二题
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
1 #include <stdio.h> 2 #include <math.h> 3 #include <string.h> 4 #include <stdlib.h> 5 #include <iostream> 6 #include <algorithm> 7 8 #define eps 1e-8 9 #define MAXX 10510 using namespace std;11 typedef struct point12 {13 double x;14 double y;15 }point;16 17 point p[MAXX],s[MAXX];18 19 bool dy(double x,double y){ return x>y+eps; }20 bool xy(double x,double y){ return x<y-eps; }21 bool dyd(double x,double y){ return x>y-eps; }22 bool xyd(double x,double y){ return x<y+eps; }23 bool dd(double x,double y){ return fabs(x-y)<eps; }24 25 double crossProduct(point a,point b,point c)26 {27 return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);28 }29 point IntersectPoint(point u1,point u2,point v1,point v2)30 {31 point ans=u1;32 double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/33 ((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));34 ans.x+=(u2.x - u1.x)*t;35 ans.y+=(u2.y - u1.y)*t;36 return ans;37 }38 39 void cut(point p[],point s[],int n,int &len)40 {41 point tp[MAXX];42 p[n]=p[0];43 for(int i=0; i<=n; i++)44 {45 tp[i] = p[i];46 }47 int cp=n,tc;48 for(int i=0; i<n; i++)49 {50 tc=0;51 for(int k=0; k<cp; k++)52 {53 if(dyd(crossProduct(p[i],p[i+1],tp[k]),0.0))//clock-wise54 s[tc++]=tp[k];55 if(xy(crossProduct(p[i],p[i+1],tp[k])*56 crossProduct(p[i],p[i+1],tp[k+1]),0.0))57 s[tc++]=IntersectPoint(p[i],p[i+1],tp[k],tp[k+1]);58 }59 s[tc]=s[0];60 for(int k=0; k<=tc; k++)61 tp[k]=s[k];62 cp=tc;63 }64 len=cp;65 }66 67 int main()68 {69 int n,i,j;70 int cas=1;71 while(scanf("%d",&n)!=EOF && n)72 {73 for(i=0 ;i<n; i++)74 {75 scanf("%lf%lf",&p[i].x,&p[i].y);76 }77 int len;78 cut(p,s,n,len);79 printf("Floor #%d\n",cas++);80 if(len)81 printf("Surveillance is possible.\n\n");82 else printf("Surveillance is impossible.\n\n");83 }84 return 0;85 }
poj 1474 Video Surveillance (半平面交)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。