Rotating Scoreboard
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 5300   Accepted: 2112

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

 
给个链接,求多边形内核,讲的挺详细:http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html
 
代码:
 #include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define exp 1e-10 struct node
{
double x;
double y;
}; node point[];//记录最开始的多边形
node q[]; //临时保存新切割的多边形
node p[]; //保存新切割出的多边形
int n,m;//n的原先的点数,m是新切割出的多边形的点数
double a,b,c; void getline(node x,node y) //获取直线ax+by+c==0
{
a=y.y-x.y;
b=x.x-y.x;
c=y.x*x.y-x.x*y.y;
} node intersect(node x,node y) //获取直线ax+by+c==0 和点x和y所连直线的交点
{
double u=fabs(a*x.x+b*x.y+c);
double v=fabs(a*y.x+b*y.y+c);
node ans;
ans.x=(x.x*v+y.x*u)/(u+v);
ans.y=(x.y*v+y.y*u)/(u+v);
return ans;
} void cut() //用直线ax+by+c==0切割多边形
{
int cutm=,i;
for(i=;i<=m;i++)
{
if(a*p[i].x+b*p[i].y+c>=) //题目是顺时钟给出点的
{ //所以一个点在直线右边的话,那么带入值就会大于等于0
q[++cutm]=p[i]; //说明这个点还在切割后的多边形内,将其保留
}
else
{
if(a*p[i-].x+b*p[i-].y+c>) //该点不在多边形内,但是它和它相邻的点构成直线与
{ //ax+by+c==0所构成的交点可能在新切割出的多边形内,
q[++cutm]=intersect(p[i-],p[i]); //所以保留交点
}
if(a*p[i+].x+b*p[i+].y+c>)
{
q[++cutm]=intersect(p[i+],p[i]);
}
}
}
for(i=;i<=cutm;i++)
{
p[i]=q[i];
}
p[cutm+]=q[];
p[]=q[cutm];
m=cutm;
} void solve()
{
int i;
for(i=;i<=n;i++)
{
p[i]=point[i];
}
point[n+]=point[];
p[n+]=p[];
p[]=p[n];
m=n;
for(i=;i<=n;i++)
{
getline(point[i],point[i+]); //根据point[i]和point[i+1]确定直线ax+by+c==0
cut(); //用直线ax+by+c==0切割多边形
}
} int main()
{
int cas,i;
//freopen("D:\\in.txt","r",stdin);
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%lf%lf",&point[i].x,&point[i].y);
}
solve();
if(m==)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return ;
}

poj3335 半交平面,多边形内核的更多相关文章

  1. bzoj 1007 半交平面简化版

    本题就是求半交平面的交包含哪些直线,而且有点特殊(一般的半交平面用双端队列,因为可能转到最开始的直线,但本题不会,所以只需要一端操作就行了). /*************************** ...

  2. 计算几何-多边形内核判定-HPI-poj3335

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 先解决一个问题, ...

  3. poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】

    <题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...

  4. Rotating Scoreboard - POJ 3335(半面相交求多边形内核)

    题目大意:RT 分析:所谓内核可以理解为在多边形内存在点可以在这个点上看到多边形内部所有的部分,当然怎么求出来就是问题的关键了.我们知道多边形的每条边都是边界值,边的左边和右边肯定是一部分属于多边形一 ...

  5. poj3335 半平面交

    题意:给出一多边形.判断多边形是否存在一点,使得多边形边界上的所有点都能看见该点. sol:在纸上随手画画就可以找出规律:按逆时针顺序连接所有点.然后找出这些line的半平面交. 题中给出的点已经按顺 ...

  6. POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)

    题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...

  7. POJ 3335 Rotating Scoreboard(半平面交求多边形核)

    题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...

  8. 【kuangbin专题】计算几何_半平面交

    1.poj3335 Rotating Scoreboard 传送:http://poj.org/problem?id=3335 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的 ...

  9. POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交

    题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...

随机推荐

  1. 关于Unity3d粒子系统的小发现(天堂3技能释放)

    导入系统给的粒子包,发现了一个问题:系统的粒子都有移动轨迹. 而自己新建的空粒子系统却没有这个功能.顺便也复习一下粒子系统. Particle System (粒子系统): Duration(持续时间 ...

  2. GNU CMAKE 笔记

    最近在调试OJ, 忙了4天多, 最后的问题是judge模块不能正常工作. judge 模块就是两个C++源文件, 它的工作是 从数据库获取用户提交的源码 测评 将测评结果写到数据库 测评部分是与数据库 ...

  3. Linux下安装webstorm

    Linux下安装webstorm 1--在webstorm官网里面下载最新的版本 WebStorm-11.0.3.tar.gz 2--创建webstorm的安装目录 #mkdir /usr/webst ...

  4. Android系统手机端抓包方法

    抓包准备 1. Android手机需要先获得root权限.一种是否获得root权限的检验方法:安装并打开终端模拟器(可通过安卓市场等渠道获得).在终端模拟器界面输入su并回车,若报错则说明未root, ...

  5. bootstrap学习总结-02 网格布局

    1  网格布局 Bootstrap 提供了一套响应式.移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. <!DOCTYPE html> ...

  6. BZOJ3282: Tree

    传送门 又是权限题= =,过了NOIp我就要去当一只权限狗! LCT裸题,get到了两个小姿势. 1.LCA操作应该在access中随时updata 2.Link操作可以更简单 void Link(i ...

  7. BZOJ2049: [Sdoi2008]Cave 洞穴勘测 Link-Cut-Tree 模板题

    传送门 搞了这么长时间Splay终于可以搞LCT了,等等,什么是LCT? $LCT$就是$Link-Cut-Tree$,是维护动态树的一个很高效的数据结构,每次修改和查询的均摊复杂度为$O(logN) ...

  8. (转)雅虎工程师提供的css初始化示例代码

    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,b ...

  9. 从Paxos到ZooKeeper-二、ZooKeeper和Paxos

    ZooKeeper为分布式应用提供了高效且可靠的分布式协调服务,提供了诸如tong'yi统一命名服务.配置管理和分布式锁等分布式的基础服务.在解决分布式数据一致性方面,ZooKeeper并没有直接采用 ...

  10. json转换成对象

    在json转换成对象时,json的key会与java 类的字段一一对应.如果没有映射上的java字段会在该数据类型上填充默认值,如int 0,String null 等. 没有映射的json key在 ...