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. PHP学习笔记 - 进阶篇(8)

    PHP学习笔记 - 进阶篇(8) 日期与时间 取得当前的Unix时间戳 UNIX 时间戳(英文叫做:timestamp)是 PHP 中关于时间与日期的一个很重要的概念,它表示从 1970年1月1日 0 ...

  2. OC7_单词个数

    // // WordManger.h // OC7_单词个数 // // Created by zhangxueming on 15/6/17. // Copyright (c) 2015年 zhan ...

  3. 大家注意:升级 win8.1 火狐浏览器 谷歌浏览器 搜狗五笔输入法 都不能用啦

    大家注意:升级 win8.1 火狐浏览器 谷歌浏览器 搜狗五笔输入法 都不能用啦 我的电脑64位 win8 thinkpad e531,8G内存 刚在线升级完8.1,发现这些问题,大家注意,有知道问题 ...

  4. SQL server 常见用法记录

        -- ============================================= -- Author:                tanghong -- Create da ...

  5. Angularjs在线编辑器

    1.TextAngular: https://github.com/fraywing/textAngular textAngular是一个强大的Text-Editor/Wysiwyg 编辑器,用于An ...

  6. IAR ERROR --- [Li006]

    今天移植代码时遇到一个比较奇葩的问题,记录如下: Error[Li006]: duplicate definitions for "Uart3"; in "E:\IAR_ ...

  7. Jquery ajax basic

    $.ajax({ url: "test.aspx?action=testaction", contentType: "application/json; charset= ...

  8. jQuery scroll(滚动)延迟加载

    延迟加载 $(window).scroll(function(){ var scrollHeight = $(document).height(); //文档高度 var scrollTop = $( ...

  9. 教你配置linux服务器登陆欢迎信息

    登录一台测试机时发现显示PS1前还显了一行’Welcome to Cloudex’的欢迎信息,真丫牛B.在linux中,设置/etc/issue和/etc/motd文件即可实现这样的登录欢迎信息. 登 ...

  10. 《疯狂的android讲义第3版》读书笔记

    第一章.开始启程,你的第一行android代码 1.android系统架构: 1)linux内核层:为底层硬件提供驱动,如显示驱动.音频驱动.照相机驱动.蓝牙驱动.Wifi驱动.电源管理等 2)系统运 ...