poj 3335 Rotating Scoreboard
来源:互联网 发布:java post 传递json 编辑:程序博客网 时间:2024/05/21 22:32
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 formn x1 y1x2 y2 ...xn yn wheren (3 ≤ n ≤ 100) is the number of vertices in the polygon, and the pair of integersxi 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
24 0 0 0 1 1 1 1 08 0 0 0 2 1 2 1 1 2 1 2 2 3 2 3 0
Sample Output
YESNO
Source
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#define eps 1e-8#define ll long long#define fo(i,j,k) for(i=j;i<=k;i++)using namespace std;const int mxn=50005;int n,h,t,ln,T;int order[mxn],que[mxn];struct point {double x,y;} p[mxn];struct line {point a,b;double ang;} l[mxn];inline int sign(double k){if(fabs(k)<eps) return 0;return k>0?1:-1;}inline double cross(point p0,point p1,point p2){return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}inline bool comp(int u,int v){int d=sign(l[u].ang-l[v].ang);if(!d) return sign(cross(l[u].a,l[v].a,l[v].b))<0;return d<0;}inline void get(line l1,line l2,point &p){double d1,d2;d1=cross(l2.a,l1.b,l1.a);d2=cross(l1.b,l2.b,l1.a);p.x=(l2.a.x*d2+l2.b.x*d1)/(d1+d2);p.y=(l2.a.y*d2+l2.b.y*d1)/(d1+d2);}inline bool judge(line l0,line l1,line l2){point p;get(l1,l2,p);return sign(cross(p,l0.a,l0.b))>0;}inline void PHI(){int i,j;sort(order,order+ln,comp);for(i=1,j=0;i<ln;i++) if(sign(l[order[i]].ang-l[order[j]].ang)>0) order[++j]=order[i];ln=j,h=0,t=1;que[0]=order[0],que[1]=order[1];fo(i,2,ln){while(h<t && judge(l[order[i]],l[que[t-1]],l[que[t]])) t--;while(h<t && judge(l[order[i]],l[que[h+1]],l[que[h]])) h++;que[++t]=order[i];}while(h<t && judge(l[order[h]],l[que[t-1]],l[que[t]])) t--;while(h<t && judge(l[order[t]],l[que[h+1]],l[que[h]])) h++;}inline void addline(double x1,double y1,double x2,double y2){l[ln].a.x=x1,l[ln].a.y=y1;l[ln].b.x=x2,l[ln].b.y=y2;l[ln].ang=atan2(x2-x1,y2-y1);order[ln]=ln,ln++;}int main(){int i,j;scanf("%d",&T);while(T--){scanf("%d",&n);fo(i,0,n-1) scanf("%lf%lf",&p[i].x,&p[i].y);for(ln=i=0;i<n-1;i++) addline(p[i].x,p[i].y,p[i+1].x,p[i+1].y);addline(p[i].x,p[i].y,p[0].x,p[0].y);PHI();if(t-h>1) printf("YES\n");else printf("NO\n");}return 0;}
- poj 3335 Rotating Scoreboard
- POJ 3335 Rotating Scoreboard
- poj 3335 Rotating Scoreboard
- POJ 3335 Rotating Scoreboard
- POJ 3335 Rotating Scoreboard
- poj 3335 Rotating Scoreboard
- POJ 3335 Rotating Scoreboard
- poj 3335 Rotating Scoreboard
- Poj 3335 Rotating Scoreboard (多边形求核)
- poj 3335 Rotating Scoreboard - 半平面交
- POJ 3335 Rotating Scoreboard (半平面交)
- poj 3335 Rotating Scoreboard
- poj 3335 Rotating Scoreboard
- Rotating Scoreboard - POJ 3335 半平面交
- POJ 3335||Rotating Scoreboard(半平面交求核
- POJ 3335 Rotating Scoreboard 半平面交
- POJ 3335 Rotating Scoreboard 半平面交
- poj 3335 Rotating Scoreboard(半平面交)
- [bzoj1054][HAOI2008]移动玩具
- Shell脚本——按行读取文件
- 建立表空间以及用户
- 如何做到优化引擎搜索SEO(有HTML,关键字,Ajax,url,内容顺序等)
- ISCC2017 writeup
- poj 3335 Rotating Scoreboard
- C++_继承与派生
- 并发,cpu,时间片轮转,原子操作
- JS获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS” 可以根据需求修改
- mysql学习日志二
- Leetcode 149. Max Points on a Line
- slub分配器实现
- java:word转pdf
- iOS控制器显示导航栏时,self.view高度变化问题