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. 使用gulp脚本配合TypeScript开发

    目标:编写TypeScript时,保存即生成js文件.   使用npm安装以下组件 gulp gulp-rename through-gulp gulp-typescript   编写gulpfile ...

  2. 第一章、C#委托和事件(Delegate、Event、EventHandler、EventArgs)

    第一章.C#委托和事件(Delegate.Event.EventHandler.EventArgs) 分类: 学习笔记-C#网络编程2012-12-08 14:10 7417人阅读 评论(3) 收藏  ...

  3. LINQ(LINQ to Entities)

    LINQ to Entities 是 LINQ 中最吸引人的部分.它让你可以使用标准的 C# 对象与数据库的结构和数据打交道.使用 LINQ to Entities 时,LINQ 查询在后台转换为 S ...

  4. jCallout 实现气泡提示

    在提交表单前.焦点转移后或者 keyup 时往往需要对输入的文本就行检验,如果输入内容不符合相关约定则要进行提示或警告,有一个叫 jCallout 的插件可以轻松实现该功能,该插件基于  jQuery ...

  5. dtcms,header显示头像和用户名,QQ互联老不通过的解决方法

    http://bbs.dtsoft.net/forum.php?mod=viewthread&tid=1742&extra=page%3D1

  6. github项目filter_firewall说明

    本文编写的目的: 本文是对上传到github上的项目进行说明.github链接:filter_firewall有任何意见或者建议可以Email:18277973721@sina.cn 项目介绍: 包过 ...

  7. 分享php中四种webservice实现的简单架构方法及实例[转载]

    [转载]http://www.itokit.com/2012/0417/73615.html 本人所了解的webservice有以下几种:PHP本身的SOAP,开源的NUSOAP,商业版的PHPRPC ...

  8. [译]Java Thread wait, notify和notifyAll示例

    Java Thread wait, notify和notifyAll示例 Java上的Object类定义了三个final方法用于不同线程间关于某资源上的锁状态交互,这三个方法是:wait(), not ...

  9. [ Web Service ] [ SOAP ] [ JSON ] [ XML ] 格式轉換

    JSON格式產生器_Demo JSON格式產生器_ObjGen - Live JSON Generator JSON格式整理_JSON Formatter & Validator Online ...

  10. php入门变量之数字

    在介绍变量时,我明确指出PHP具有整型和浮点型(小数)数字类型.但是,依据我的经验,这两种类型都可以归类到一般的数字之下(在极大程度上是这样的). 下面列举下PHP中有效的数字类型的变量: 8 3.1 ...