poj-1474 Video Surveillance

75 篇文章 0 订阅
30 篇文章 0 订阅

题意:

判断多边形是否存在核;

点集顺时针或逆时针给出,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;
}







  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值