POJ 3335: Rotating Scoreboard 半平面交

Rotating Scoreboard
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 7505 Accepted: 3008

Description

This year, ACM/ICPC World finals will be held in a hall in form of a simple polygon. The coaches and spectators are seated along the edges of the polygon. We want to place a rotating scoreboard somewhere in the hall such that a spectator sitting anywhere on the boundary of the hall can view the scoreboard (i.e., his line of sight is not blocked by a wall). Note that if the line of sight of a spectator is tangent to the polygon boundary (either in a vertex or in an edge), he can still view the scoreboard. You may view spectator's seats as points along the boundary of the simple polygon, and consider the scoreboard as a point as well. Your program is given the corners of the hall (the vertices of the polygon), and must check if there is a location for the scoreboard (a point inside the polygon) such that the scoreboard can be viewed from any point on the edges of the polygon.

Input

The first number in the input line, T is the number of test cases. Each test case is specified on a single line of input in the form n x1 y1 x2 y2 ... xn yn where n (3 ≤ n ≤ 100) is the number of vertices in the polygon, and the pair of integers xi yi sequence specify the vertices of the polygon sorted in order.

Output

The output contains T lines, each corresponding to an input test case in that order. The output line contains either YES or NO depending on whether the scoreboard can be placed inside the hall conforming to the problem conditions.

Sample Input

2
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

Sample Output

YES
NO

Source


这仍然是一道半平面交模板

但是数据比较强

便于发现bug 弱鸡的福音


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

typedef double db;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}

const int N=110;
const db eps=1e-8;

struct point
{
	db x,y;
	
	friend point operator +(const point &a,const point &b)
	{return (point){a.x+b.x,a.y+b.y};}
	
	friend point operator -(const point &a,const point &b)
	{return (point){a.x-b.x,a.y-b.y};}
	
	friend db cross(const point &x,const point &y,const point &bas)
	{
		point a(x-bas),b(y-bas);
		return a.x*b.y-a.y*b.x;
	}
}p[N];

int scnt;
struct segment
{
	point X,Y;db angle;
	
	friend bool operator <(const segment &a,const segment &b)
	{
		if(abs(a.angle-b.angle)<eps) return cross(a.Y,a.X,b.X)>0;
		return a.angle<b.angle;
	}
	
	friend point get_node(const segment &a,const segment &b)
	{
		point res;
		db s[2];
		s[0]=cross(a.X,a.Y,b.X);
		s[1]=cross(a.Y,a.X,b.Y);
		res.x=(b.Y.x*s[0]+b.X.x*s[1])/(s[0]+s[1]);
		res.y=(b.Y.y*s[0]+b.X.y*s[1])/(s[0]+s[1]);
		return res;
	}
	
	friend bool check(const segment &a,const segment &b,const segment &c)
	{
		point tmp(get_node(a,b));
		return cross(c.Y,tmp,c.X)<0;
	}
}seg[N];

inline void add_seg(const point &x,const point &y)
{
	seg[++scnt].X=x;seg[scnt].Y=y;
	seg[scnt].angle=atan2(y.y-x.y,y.x-x.x);
}

int n;

int q[N];

int hpi()
{
	sort(seg+1,seg+1+n);
	register int i,tot(1),head(0),tail(2);
	for(i=2;i<=n;++i)
		if(seg[i].angle-seg[tot].angle>eps)
			seg[++tot]=seg[i];
	q[0]=1,q[1]=2;
	for(i=3;i<=tot;++i)
	{
		while(head<tail-1 && check(seg[q[tail-1]],seg[q[tail-2]],seg[i])) tail--;
		while(head<tail-1 && check(seg[q[head]],seg[q[head+1]],seg[i])) head++;
		q[tail++]=i;
	}
	while(head<tail-1 && check(seg[q[tail-1]],seg[q[tail-2]],seg[q[head]])) tail--;
	while(head<tail-1 && check(seg[q[head]],seg[q[head+1]],seg[q[tail-1]])) head++;
	return tail-head;
}

int main()
{
	register int i,T=read();
	while(T--)
	{
		scnt=0;
		n=read();
		for(i=1;i<=n;++i)
			p[i].x=read(),p[i].y=read();
		p[n+1]=p[1];
		for(i=n;i;--i)
			add_seg(p[i+1],p[i]);
		hpi()>2 ? puts("YES") : puts("NO");
	}
	return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值