Rotating Scoreboard

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 nx1y1x2y2 ... xnyn where n (3 ≤ n ≤ 100) is the number of vertices in the polygon, and the pair of integers xiyi 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<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define Maxn 100010 const double eps=0.0001;
const double pi=3.141592653; struct P {double x,y;};
struct L {P a,b;double slop;}l[Maxn],p[Maxn];
int len; double Dot(P x,P y) {return x.x*y.x+x.y*y.y;}
double Cross(P x,P y) {return x.x*y.y-x.y*y.x;} P operator - (P x,P y)
{
P tt;
tt.x=x.x-y.x;
tt.y=x.y-y.y;
return tt;
} P operator + (P x,P y)
{
P tt;
tt.x=x.x+y.x;
tt.y=x.y+y.y;
return tt;
} P operator * (P x,double y)
{
P tt;
tt.x=x.x*y;
tt.y=x.y*y;
return tt;
} bool operator < (L x,L y) {return (x.slop==y.slop)?(Cross(x.b-x.a,y.b-x.a)<):(x.slop<y.slop);} P inter(L x,L y)
{
P nw=y.a-x.a;
P X=x.b-x.a,Y=y.b-y.a;
double tt;
tt=Cross(nw,X)/Cross(X,Y);
return y.a+Y*tt;
} bool jud(L x,L y,L z)
{
// if(x.slop==-y.slop) return 1;
// if(x.slop-pi-y.slop<=eps&&x.slop-pi-y.slop>=-eps) return 1;
// if(y.slop-pi-x.slop<=eps&&y.slop-pi-x.slop>=-eps) return 1;
//???????
P nw=inter(x,y);
return Cross(z.b-z.a,nw-z.a)<;
} int cnt; void op()
{
for(int i=;i<=cnt;i++)
{
printf("%.2lf %.2lf %.2lf %.2lf = %.2lf\n",l[i].a.x,l[i].a.y,l[i].b.x,l[i].b.y,l[i].slop);
}
printf("\n");
} void opp(int L,int R)
{
for(int i=L;i<=R;i++)
{
printf("%.2lf %.2lf %.2lf %.2lf = %.2lf\n",p[i].a.x,p[i].a.y,p[i].b.x,p[i].b.y,p[i].slop);
}
printf("\n");
} void ffind()
{
sort(l+,l++cnt);
// op();
int tot=;
for(int i=;i<=cnt;i++)
{
if(l[i].slop!=l[tot].slop) l[++tot]=l[i];
}
cnt=tot;
if(cnt<=) {printf("NO\n");return;}
// op();
p[]=l[];p[]=l[];
int L=,R=;
for(int i=;i<=cnt;i++)
{
while(R>L&&jud(p[R],p[R-],l[i])) R--;
while(R>L&&jud(p[L],p[L-],l[i])) L++;
p[++R]=l[i];
}
// if(R>L&&jud(p[L],p[L+1],p[R])<0) R--;
if(L<R&&jud(p[R-],p[R],p[L])) R--;
// opp(L,R);
if(R-L+<=) printf("NO\n");
else printf("YES\n");
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
P now,ft;
scanf("%lf%lf",&ft.x,&ft.y);
now=ft;
cnt=;
for(int i=;i<=n;i++)
{
P nw;
scanf("%lf%lf",&nw.x,&nw.y);
l[++cnt].a=nw;l[cnt].b=now;
now=nw;
}
l[++cnt].a=ft;l[cnt].b=now;
for(int i=;i<=cnt;i++) l[i].slop=atan2(l[i].b.x-l[i].a.x,l[i].b.y-l[i].a.y);
// op();
ffind();
}
return ;
}

2016-12-26 18:51:45

【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)的更多相关文章

  1. POJ 3335 Rotating Scoreboard(多边形的核)

    题目链接 我看的这里:http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html 然后整理一下当做模版.0换成eps,会wa,应该要 ...

  2. poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 25 ...

  3. poj 3335 Rotating Scoreboard - 半平面交

    /* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...

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

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

  5. poj 3335 Rotating Scoreboard (Half Plane Intersection)

    3335 -- Rotating Scoreboard 给出一个多边形,要求判断它的内核是否存在. 还是半平面交的题,在这道题中,公告板允许其所在位置与直线共线也算是可见,于是我们就可以将每一条直线微 ...

  6. POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)

    题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...

  7. POJ 3335 Rotating Scoreboard 半平面交求核

    LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...

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

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

  9. poj 3335 Rotating Scoreboard

    http://poj.org/problem?id=3335 #include <cstdio> #include <cstring> #include <algorit ...

随机推荐

  1. 第二篇、为UITableViewCell 高度自适应加速 缓存cell的高度

    通过NSCache缓存已经算好的行高 @interface ZHCellHeightCalculator : NSObject //系统计算高度后缓存进cache -(void)setHeight:( ...

  2. Cocos2d-x开发实例:使用Lambda 表达式

    在Cocos2d-x 3.0之后提供了对C++11标准[1]的支持,其中的Lambda[2]表达式使用起来非常简洁.我们可以使用Lambda表达式重构上一节的实例. 我们可以将下面的代码: liste ...

  3. iMAC——关闭自动弹出手机照片

    有时当自己的iPhone手机插入一台iMAC电脑时,会自动弹出自己iPhone手机的照片. 这相当影响人的隐私等等,所以顺便将方法(参考网络的)小记一篇博客. 一.OS X 10.10以上用户解决办法 ...

  4. Java+FlexPaper+swfTools 文档在线预览demo

    1.概述 主要原理 1.通过第三方工具openoffice,将word.excel.ppt.txt等文件转换为pdf文件 2.通过swfTools将pdf文件转换成swf格式的文件 3.通过FlexP ...

  5. Java流的正确关闭方式

    因为流是无论如何一定要关闭的,所以要写在finally里.如下: BufferedReader reader = null; try { reader = (BufferedReader) getRe ...

  6. python mysqldb使用dictcursor

    python在使用MySQLdb库的时候,如下方法默认获取的cursor的结果集是tuple结构的. con = MySQLdb.connect('host',port,'username','pas ...

  7. 写了个Linux包过滤防火墙

    花几天写了个so easy的Linux包过滤防火墙,估计实际意义不是很大.防火墙包括用户态执行程序和内核模块,内核模块完全可以用iptable代替.由于在编写的过程一开始写的是内核模块所以就直接用上来 ...

  8. Android使用百度地图API实现GPS步行轨迹

    百度地图Android SDK下载:http://developer.baidu.com/map/sdkandev-download.htm 下面是效果: 采样点取得太频繁所以看起来像是一个个点... ...

  9. ACM俱乐部 字符串

    数制转换分数: 2 时间限制:1 秒 内存限制:32 兆 特殊判题: 否 提交:59 解决: 24 标签 进制转换 题目描述 求任意两个不同进制非负整数的转换(2进制-16进制),所给整数在long所 ...

  10. SYBASE时间计算

    以摘录了计算月初,月末,上月同日,下月同日,上年同日,下年同日(年有闰月问题),各种函数输出格式. 可以写到存储过程中也可单独使用. Sybase日期函数 文章分类:数据库 关键字: sybase日期 ...