poj 1474 Video Surveillance (半平面交)

原创 2017年01月03日 09:11:49

Video Surveillance
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3990   Accepted: 1781

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

[Submit]   [Go Back]   [Status]   [Discuss]


题目大意:判断多边形是否有内核

题解:半平面交

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 203
#define eps 1e-8
#define inf 1000000000
using namespace std;
struct vector {
	double x,y;
	vector (double X=0,double Y=0){
		x=X,y=Y;
	}
}a[N],p[N];
int n,m;
typedef vector point;
vector operator -(vector a,vector b){
	return vector (a.x-b.x,a.y-b.y);
}
vector operator +(vector a,vector b){
	return vector (a.x+b.x,a.y+b.y);
}
vector operator *(vector a,double t){
	return vector (a.x*t,a.y*t);
}
void init()
{
	m=0;
	p[m++]=point(inf,inf);
	p[m++]=point(-inf,inf);
	p[m++]=point(-inf,-inf);
	p[m++]=point(inf,-inf);
}
double cross(vector a,vector b)
{
	return a.x*b.y-a.y*b.x;
}
point glt(point a,point a1,point b,point b1)
{
	vector v=a1-a; vector w=b1-b;
	vector u=a-b;
	double t=cross(w,u)/cross(v,w);
	return a+v*t;
}
void cut(point a,point b)
{
	int cnt=0;
	point tmp[N];
	memset(tmp,0,sizeof(tmp));
	for (int i=0;i<m;i++){
		double c=cross(b-a,p[i]-a);
		double d=cross(b-a,p[(i+1)%m]-a);
		if (c>=0) tmp[cnt++]=p[i];
		if (c*d<0)
		 tmp[cnt++]=glt(a,b,p[i],p[(i+1)%m]);
	}
	m=cnt;
	for (int i=0;i<cnt;i++) p[i]=tmp[i];
}
int main()
{
	freopen("a.in","r",stdin);
	int t=0;
	while (true){
		scanf("%d",&n);
		t++;
		if (!n) break;
		for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
		a[n+1]=a[1];
		init();
		for (int i=2;i<=n+1;i++){
			cut(a[i],a[i-1]);
			if (!m) break;
		}
		printf("Floor #%d\n",t);
		if (m) printf("Surveillance is possible.\n");
		else printf("Surveillance is impossible.\n");
		printf("\n");
	}
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

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

Language: Default Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K T...

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

题目大意:一个楼有很多层,每一层是一个多多边形,问每一层是否有点能够看到这一层的全貌。 思路:半平面交解多边形内核存在性,裸题。题中怎么没写数据范围?。。让我还re几次。。 CODE:...

POJ 1474 || Video Surveillance(半平面交

拿上一题代码改一下直接就过了,躶题233 我连题目都没看 看着题目的配图感觉都是那个意思,随便一交就AC了。66666.。。。 #include #include #include #incl...
  • FXXKI
  • FXXKI
  • 2015-05-09 20:45
  • 267

POJ 1474 Video Surveillance (多边形内核判断)

【题目链接】click here~~ 【题目大意】:多边形内核的判断 【思路】:模板题 代码: /* * Problem: POJ No.1474 * Running time: 125MS * Co...

POJ1474-Video Surveillance

Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3190...

POJ 1474 Video Surveillance

POJ 1474 Video Surveillance 半平面交模板。。。 就是拿来测试的。。。。 #include #include #include #include #includ...

poj-1474 Video Surveillance

题意: 判断多边形是否存在核; 点集顺时针或逆时针给出,n 题解: 半平面交模板题; 多边形的核就在组成多边形的半平面的交上; 也可以顺便说明多边形的核若存在则一定是凸的; 原因...

boj 35 Video Surveillance 半平面交求多边形的核

//============================================================================ // Name : 35.c...

poj 1474 半平面交求多边形的核

【题意】 是否能在房间中找到一个位置来安装摄像头,使摄像头能监控到房间的每个角落。在平面图上,房间的墙只有横和竖的,没有斜的。 【题解】 判断多边形是否存在核。用半平面交判断。 【代码】 ...

【POJ1474】监控摄像头 半平面交

题目描述   一个著名的仓库管理公司SERKOI 请你为其安装一套闭路监视系统,由于SERKOI 财力有限,每个房间只能安装一台摄像机,不过其镜头可以向任何方向转换。 请你写一个程序,对于给定的房...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)