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.

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.

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 105
10 using namespace std;
11 typedef struct point
12 {
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-wise
54                 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 }

时间: 2025-01-01 05:43:54

poj 1474 Video Surveillance (半平面交)的相关文章

POJ 1474 Video Surveillance 半平面交求多边形是否有核

裸的半平面交求多边形是否有核. 多边形的核: 在多边形核上的点可以看到多边形的所有顶点,凸多边形的核显然就是多边形本身. 多边形的核是一个凸包,对多边形的所有边都做向着多边形的半平面交在判断一下是否构成凸包就可以了 一样的题目还有POJ3335 Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3438   Accepted: 1523 Description A friend of y

POJ 1474 Video Surveillance 半平面交求多边形内核存在性

题目大意:一个楼有很多层,每一层是一个多多边形,问每一层是否有点能够看到这一层的全貌. 思路:半平面交解多边形内核存在性,裸题.题中怎么没写数据范围?..让我还re几次.. CODE: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 3010 #define EPS 1e-8 #de

POJ1474 Video Surveillance(半平面交)

很多道相似的半平面交,但只过了这个,心都碎了.. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 7

POJ 1474 Video Surveillance 半平面交

和POJ 3130,POJ 3335一样.求多边形的核 #include <iostream> #include <cstdio> #include <cmath> #define eps 1e-18 using namespace std; const int MAXN = 105; double a, b, c; int n, cnt; struct Point { double x, y; }point[MAXN], p[MAXN], tp[MAXN]; void

poj1474Video Surveillance(半平面交)

链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. 1 #include<iostream> 2 #include <stdio.h> 3 #include <math.h> 4 #define eps 1e-8 5 using namespace std; 6 const int MAXN=210; 7 int m; 8 double r; 9 int cCnt,curCnt;//此时cCnt为最终切割得到的多边形的顶

poj 3384 Feng Shui 半平面交的应用 求最多覆盖凸多边形的面积的两个圆 的圆心坐标

题目来源: http://poj.org/problem?id=3384 分析: 用半平面交将多边形的每条边一起向"内"推进R,得到新的多边形(半平面交),然后求多边形的最远两点. 代码如下: const double EPS = 1e-10; const int Max_N = 105 ; struct Point{ double x,y; Point(){} Point(double x, double y):x(x),y(y){} Point operator - (Point

POJ 2451 nlog(n)半平面交裸题。

前言       最近学习C#,不过好在当初考计算机二级学习过C++,刚上手没有对C#感到很恐惧.C#视频也看了几天 了,总感觉不总结一下心里没底,现在跟着我从头走进C#之旅吧.     C#是以后总面向对象的编程语言(OOP),C#是从C和C++派生出来的,主要用于开发可以运行在.NET平台 上的应用程序.随着.NET的发展,C#语言简单.现代.面向对象和类型安全显示了一定的优势.     下面我就介绍一些初学者不太理解的一些东西.   C#有以下突出的特点       (1)语法简洁.不允许

POJ 1279 Art Gallery 半平面交求多边形核

第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内,否则出现在左边,就可能会有交点,将交点求出加入. //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #inc

POJ 1279 Art Gallery 半平面交+求多边形核的面积

裸的:半平面交+求多边形核的面积 Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5735   Accepted: 2419 Description The art galleries of the new and very futuristic building of the Center for Balkan Cooperation have the form of polygons (not