poj-1474 Video Surveillance

题意:

判断多边形是否存在核;

点集顺时针或逆时针给出,n<=100;

题解:

半平面交模板题;

多边形的核就在组成多边形的半平面的交上;

也可以顺便说明多边形的核若存在则一定是凸的;

原因似乎画画图是比较显然的;

一个地方被挡住一定是因为那被另一条边挡住了嘛;

注意半平面交的判断点与直线位置关系要用>=号;

此题买一送二,我大胆地在提交框里改输出然后光荣的WA了= =

poj-1474 poj-3130 poj-3335

代码:

#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 110
using namespace std;
const double EPS=1e-10;
const double pi=acos(-1.0);
struct Point
{
	double x,y;
	void read()
	{
		scanf("%lf%lf",&x,&y);
	}
	Point operator +(Point a)
	{
		a.x=x+a.x,a.y=y+a.y;
		return a;
	}
	Point operator -(Point a)
	{
		a.x=x-a.x,a.y=y-a.y;
		return a;
	}
	double operator ^(Point a)
	{
		return x*a.y-y*a.x;
	}
	friend Point operator *(double a,Point b)
	{
		b.x=a*b.x,b.y=a*b.y;
		return b;
	}
}a[N],p[N];
struct Line
{
	Point p,v;
	double alpha;
	void build(Point a,Point b)
	{
		p=a,v=b-a;
		alpha=atan2(v.y,v.x);
	}
	friend bool operator <(Line a,Line b)
	{
		return a.alpha<b.alpha;
	}
	friend Point Cross(Line a,Line b)
	{
		Point u=a.p-b.p;
		double temp=(b.v^u)/(a.v^b.v);
		return a.p+temp*a.v;
	}
}l[N],q[N];
bool Onleft(Line a,Point b)
{
	Point u=b-a.p;
	return (a.v^u)>=0;
}
bool HPI(int n)
{
	int i,st,en;
	sort(l+1,l+n+1);
	q[st=en=1]=l[1];
	for(i=2;i<=n;i++)
	{
		while(st<en&&!Onleft(l[i],p[en-1]))
			en--;
		while(st<en&&!Onleft(l[i],p[st]))
			st++;
		if(fabs(l[i].v^q[en].v)<EPS)
			q[en]=Onleft(q[en],l[i].p)?l[i]:q[en];
		else
			q[++en]=l[i];
		if(st<en)
			p[en-1]=Cross(q[en-1],q[en]);
	}
	while(st<en&&!Onleft(q[st],p[en-1]))
		en--;
	return en-st>=2;
}
int main()
{
	int c,T,n,m,i,j,k;
	c=0;
	while(scanf("%d",&n)&&n)
	{
		for(i=1;i<=n;i++)
			a[i].read();
		for(i=1;i<=n;i++)
			l[i].build(a[i+1>n?1:i+1],a[i]);
		printf("Floor #%d\n",++c);
		if(HPI(n))
			puts("Surveillance is possible.");
		else
			puts("Surveillance is impossible.");
		putchar('\n');
	}
	return 0;
}
时间: 2024-10-05 03:09:37

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

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 半平面交

和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

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

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

Video Surveillance POJ - 1474 (半平面交)

Video Surveillance POJ - 1474 题意:多边形是否有内核 思路:平面半交题,注意直线的存入顺序 1 // 2 // Created by HJYL on 2020/2/6. 3 // 4 #include<iostream> 5 #include<stdio.h> 6 #include<algorithm> 7 #include<math.h> 8 using namespace std; 9 typedef long long l

POJ 1474 多边形的核(半平面交)

Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3145   Accepted: 1391 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 ins

poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积

1 /*************** 2 poj 3335 点序顺时针 3 ***************/ 4 #include <iostream> 5 #include <cmath> 6 #include <algorithm> 7 using namespace std; 8 const double eps = 1e-8; 9 const double maxn = 0x7f7f7f7f; 10 int dcmp(double x){ 11 if(fabs(

POJ 1474

半平面交模板 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int MAXN=110; const double eps=1e-8; struct point { double x,y; }; point pts[MAXN],p[MAXN],q[MAX

半平面交 模板 poj 3335 poj 3130 poj 1474 判断半平面交是否为空集

半平面交模板 const double pi= acos(-1.0); #define arc(x) (x / 180 * pi) const double EPS = 1e-8; const int Max_N = 105; struct Point{ double x,y; Point(){} Point(double x, double y):x(x),y(y){} Point operator - (Point p){ return Point(x- p.x , y - p.y ) ;

uva 588 - Video Surveillance(半平面相交)

题目链接:uva 588 - Video Surveillance 求出多边形的核,如果非0即为可行,注意核退化成直线和点都是可以的,所以不能用面积去判断. #include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <complex> #include <algorithm> using namespace std; typedef