POJ3335Rotating Scoreboard【半平面交判断多边形是否存在内核】
来源:互联网 发布:gid软件下载 编辑:程序博客网 时间:2024/06/07 11:38
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
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
题意:给定多边形的顶点坐标判断是否存在内核;
第一道半平面交参考博客:http://blog.csdn.net/accry/article/details/6070621
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespace std;struct point{double x,y;}A[105],p[105],q[105];int N;int endcnt,tempcnt; double r;void getline(point p1,point p2,double &a,double &b,double &c){a=p2.y-p1.y;b=p1.x-p2.x;c=p2.x*p1.y-p2.y*p1.x;}void init(){for(int i=1;i<=N;++i){p[i]=A[i];}p[N+1]=p[1];p[0]=p[N];endcnt=N;}point intersect(point p1,point p2,double a,double b,double c){double u=fabs(a*p1.x+b*p1.y+c);double v=fabs(a*p2.x+b*p2.y+c);point temp;temp.x=(p1.x*v+p2.x*u)/(u+v);temp.y=(p1.y*v+p2.y*u)/(u+v);return temp;}void cut(double a,double b,double c){tempcnt=0;for(int i=1;i<=endcnt;++i){if(a*p[i].x+b*p[i].y+c>=0)q[++tempcnt]=p[i];else {if(a*p[i-1].x+b*p[i-1].y+c>0)q[++tempcnt]=intersect(p[i],p[i-1],a,b,c);if(a*p[i+1].x+b*p[i+1].y+c>0)q[++tempcnt]=intersect(p[i],p[i+1],a,b,c);}}for(int i=1;i<=tempcnt;++i){p[i]=q[i];}p[tempcnt+1]=q[1];p[0]=p[tempcnt];endcnt=tempcnt;}void guizheng(){int i;for(i=1;i<=N;++i){q[i]=A[N-i+1];}for(i=1;i<=N;++i){A[i]=q[i];}}void solve(){//guizheng();init();for(int i=1;i<=N;++i){double a,b,c;getline(A[i],A[i+1],a,b,c);cut(a,b,c);}}int main(){int t,i,j,k;scanf("%d",&t);while(t--){scanf("%d",&N);for(i=1;i<=N;++i){scanf("%lf%lf",&A[i].x,&A[i].y);}A[N+1]=A[1];solve();if(endcnt>0)printf("YES\n");else printf("NO\n");}return 0;}
- POJ3335Rotating Scoreboard【半平面交判断多边形是否存在内核】
- poj 3335 Rotating Scoreboard(判断多边形是否有核+半平面交)
- POJ 3335 Rotating Scoreboard 半平面交求多边形内核
- poj1474Video Surveillance【半平面交判断内核是否存在】
- Poj 3335 Rotating Scoreboard [半平面交判断内核]
- POJ 3335(半平面交—判断多边形的核是否存在)
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
- poj 3335 Rotating Scoreboard(半平面交,求解多边形内核)
- 计算几何--(半平面判断多边形是否存在内核以及内核面积计算)
- POJ 3130 How I Mathematician Wonder What You Are! 半平面交求多边形内核是否存在
- POJ 3335 Rotating Scoreboard (半平面交判断)
- 半平面交,求解多边形内核
- 半平面交,求解多边形内核
- 半平面交,求解多边形内核
- 半平面交 poj 3335(判断是否有内核) poj 3525 (半平面交+二分)
- POJ 1474 Video Surveillance 半平面交求多边形内核存在性
- POJ 3130 How I Mathematician Wonder What You Are! (半平面交+多边形内核判断)
- POJ3335(判断多边形内核是否存在)
- C++ sort函数
- Android笔记:20150406
- C++ inline
- (转)c++类的成员函数存储方式(是否属于类的对象)---一道面试题引发的思考
- C++ 基本知识
- POJ3335Rotating Scoreboard【半平面交判断多边形是否存在内核】
- HTTP详解1-工作原理
- HTTP详解2-请求、响应、缓存
- Android客户端写Cookie和内嵌的网页实现登录状态的同步
- C++ 强制类型转换
- linux用户态和内核态理解
- Android view中的requestLayout和invalidate方法
- volatile 关键字
- vs2010下编译osip2和eXosip2的4.0.0版的静态库及搭建开发环境