【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
Rotating ScoreboardDescription
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 0Sample Output
YES
NOSource

#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 (多边形的核- - 半平面交应用)的更多相关文章
- POJ 3335 Rotating Scoreboard(多边形的核)
题目链接 我看的这里:http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html 然后整理一下当做模版.0换成eps,会wa,应该要 ...
- poj 3335 Rotating Scoreboard(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- POJ 3335 Rotating Scoreboard(半平面交求多边形核)
题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...
- poj 3335 Rotating Scoreboard (Half Plane Intersection)
3335 -- Rotating Scoreboard 给出一个多边形,要求判断它的内核是否存在. 还是半平面交的题,在这道题中,公告板允许其所在位置与直线共线也算是可见,于是我们就可以将每一条直线微 ...
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...
- POJ 3335 Rotating Scoreboard 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- poj 3335 Rotating Scoreboard
http://poj.org/problem?id=3335 #include <cstdio> #include <cstring> #include <algorit ...
随机推荐
- CSS选择器介绍
一.元素选择器 E{...} 二.属性选择器 E[attr]{...}:指定该CSS对具有attr的元素起作用: E[attr=value]{...}::指定该CSS对具有attr的值为value的元 ...
- 在O(1)时间删除链表结点
题目:给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点. 链表结点与函数的定义如下: struct ListNode { int m_nValue; ListNode* m_p ...
- 暑假集训(4)第二弹 -----递推(hdu2254)
题意概括:上次小A在你的帮助下成功炼成贤者法阵的第一部分——三角分隔,现在他准备绘制法阵的第二部分——莫测矩形. 而他又遇到了一个问题,他不知道不同矩形到底有多少个. 秉持帮人帮到底,送佛送到西的基本 ...
- opencv 手写选择题阅卷 (一)表格设计与识别
(一)答题表格设计与识别 实际设计好的表格如下图 为了图像精确,表格和四角的标记都是由程序生成的,文字和数据是后期排版软件添加上去的. 图中四角的四个黑方块主要用来定位表格,然后就可以切割出每个单元格 ...
- Sublime Text 破解
引言 放假三天,呆家里把win7换成了win8.1,接着玩起了hyperv,试着装了个windows xp虚拟机,体验很不错.不过对linux系统的支持不怎么样,装了个ubuntu,体验相当差!闲着无 ...
- Qt移植 Window --Linux
1.把源代码复制到Linux目录,使用qmake命令,注意在shell中直接使用qmake命令注意设置PATH环境变量 2. 在目录中会生成Makeflie文件 3. make即可 /usr/bin/ ...
- jquery——ajax加载后的内容,单击事件失效
使用delegate(),on()绑定事件,可以将事件绑定到其祖先元素上,这样以后加载出来的元素,单击事件仍然有效
- 【CLR VIA C#】读书笔记
工作几年了才看,记录下笔记备忘. 章节 笔记 1.CLR的执行模型 公共语言运行时(Common Language Runtime,CLR) 源代码-->编译器检查语法和分析源代码-->托 ...
- MYSQL数据库主主同步实战
MYSQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护日志文件的一个索引以跟踪日志循环.当一个从服务器连接到主服务 ...
- 【Java Web】Eclipse中配置Marven环境
1 Marven简介 Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具,由Apache软件基金会所提供.基于项目对象模型(缩写:POM)概念,Maven利用一个中央信 ...