poj 3335 Rotating Scoreboard(半平面交)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 6420 | Accepted: 2550 |
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
- /*
- poj 3335 Rotating Scoreboard(半平面交)
- 给一个图形,判断是否存在一个位置能够观察到图形内所有的位置
- 即一个图形的核
- 输入是顺时针,需要倒一下
- hhh-2016-05-08 21:18:33
- */
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <string>
- #include <cstdio>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #include <functional>
- #include <map>
- using namespace std;
- #define lson (i<<1)
- #define rson ((i<<1)|1)
- typedef long long ll;
- using namespace std;
- const int maxn = 1010;
- const double PI = 3.1415926;
- const double eps = 1e-8;
- int sgn(double x)
- {
- if(fabs(x) < eps) return 0;
- if(x < 0)
- return -1;
- else
- return 1;
- }
- struct Point
- {
- double x,y;
- Point() {}
- Point(double _x,double _y)
- {
- x = _x,y = _y;
- }
- Point operator -(const Point &b)const
- {
- return Point(x-b.x,y-b.y);
- }
- double operator ^(const Point &b)const
- {
- return x*b.y-y*b.x;
- }
- double operator *(const Point &b)const
- {
- return x*b.x + y*b.y;
- }
- };
- struct Line
- {
- Point s,t;
- double k;
- Line() {}
- Line(Point _s,Point _t)
- {
- s = _s;
- t = _t;
- k = atan2(t.y-s.y,t.x-s.x);
- }
- Point operator &(const Line &b) const
- {
- Point res = s;
- double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t));
- res.x += (t.x-s.x)*ta;
- res.y += (t.y-s.y)*ta;
- return res;
- }
- };
- bool HPIcmp(Line a,Line b)
- {
- if(fabs(a.k-b.k) > eps) return a.k<b.k;
- return ((a.s-b.s)^(b.t-b.s)) < 0;
- }
- Line li[maxn];
- void HPI(Line line[],int n,Point res[],int &resn)
- {
- int tot =n;
- sort(line,line+n,HPIcmp);
- tot = 1;
- for(int i = 1; i < n; i++)
- {
- if(fabs(line[i].k - line[i-1].k) > eps)
- line[tot++] = line[i];
- }
- int head = 0,tail = 1;
- li[0] = line[0];
- li[1] = line[1];
- resn = 0;
- for(int i = 2; i < tot; i++)
- {
- if(fabs((li[tail].t-li[tail].s)^(li[tail-1].t-li[tail-1].s)) < eps||
- fabs((li[head].t-li[head].s)^(li[head+1].t-li[head+1].s)) < eps)
- return;
- while(head < tail && (((li[tail] & li[tail-1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps)
- tail--;
- while(head < tail && (((li[head] & li[head+1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps)
- head++;
- li[++tail] = line[i];
- }
- while(head < tail && (((li[tail] & li[tail-1]) - li[head].s) ^ (li[head].t-li[head].s)) > eps)
- tail--;
- while(head < tail && (((li[head] & li[head-1]) - li[tail].s) ^ (li[tail].t-li[tail].t)) > eps)
- head++;
- if(tail <= head+1)
- return;
- for(int i = head;i < tail;i++)
- res[resn++] = li[i]&li[i+1];
- if(head < tail-1)
- res[resn++] = li[head]&li[tail];
- }
- Point lis[maxn];
- Line line[maxn];
- int main()
- {
- //freopen("in.txt","r",stdin);
- int n,T;
- scanf("%d",&T);
- while(T--)
- {
- scanf("%d",&n);
- for(int i = 0;i < n;i++)
- {
- scanf("%lf%lf",&lis[i].x,&lis[i].y);
- }
- reverse(lis,lis+n);
- int ans;
- for(int i = 0;i < n;i++)
- {
- line[i] = Line(lis[i],lis[(i+1)%n]);
- }
- HPI(line,n,lis,ans);
- if(ans)
- printf("YES\n");
- else
- printf("NO\n");
- }
- return 0;
- }
poj 3335 Rotating Scoreboard(半平面交)的更多相关文章
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- POJ 3384 Feng Shui 半平面交
题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...
- 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 3335 Rotating Scoreboard
http://poj.org/problem?id=3335 #include <cstdio> #include <cstring> #include <algorit ...
- POJ 2540 Hotter Colder --半平面交
题意: 一个(0,0)到(10,10)的矩形,目标点不定,从(0,0)开始走,如果走到新一点是"Hotter",那么意思是离目标点近了,如果是"Colder“,那么就是远 ...
- POJ 3335 Rotating Scoreboard(多边形的核)
题目链接 我看的这里:http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html 然后整理一下当做模版.0换成eps,会wa,应该要 ...
随机推荐
- android context获取目录详解
获取 sqlite系统数据库路径 方式1: ApkInfo apkInfo = new ResourceUtil(context).getApkInfo(); APP_PATH = new Strin ...
- 【iOS】swift-通过JS获取webView的高度
let webHeightStr = webView.stringByEvaluatingJavaScriptFromString("document.body.scrollHeight& ...
- hdu 5274 Dylans loves tree
Dylans loves tree http://acm.hdu.edu.cn/showproblem.php?pid=5274 Time Limit: 2000/1000 MS (Java/Othe ...
- .NET Core装饰模式和.NET Core的Stream
该文章综合了几本书的内容. 某咖啡店项目的解决方案 某咖啡店供应咖啡, 客户买咖啡的时候可以添加若干调味料, 最后要求算出总价钱. Beverage是所有咖啡饮料的抽象类, 里面的cost方法是抽象的 ...
- a标签传递参数
a标签传递参数 单个参数:参数名称前面跟 ? <a href="localhost:8080/arguments?id=1">单个参数</a> 多个参数 ...
- nyoj 复杂度
复杂度 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) for(k=j+1;k ...
- PHP处理上传文件
HTML中使用type = 'file'类型的表单可以向服务器上传文件: 上传文件的表单必须在form中定义enctyp = 'multipart/form-data': HTML代码如下: < ...
- javaScript识别网址文本并转为链接文本
最近项目有个需求:用户之间发送消息时,如果发送者输入的信息中含有网址文本,要在接受者界面中显示网址链接,点击该链接直接跳转到网页.这个功能和 QQ 发送网址文本的效果非常像,可以说是一模一样的. 思路 ...
- javascript中获取dom元素的高度和宽度
javascript中获取dom元素高度和宽度的方法如下: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网 ...
- SpringCloud的应用发布(三)vmvare+linux,xftp,xshell连接linux失败
Vmvare内的linux虚拟机已经启动,但是 xftp和xshell连接不上? 环境信息:子网 192.168.136.* linux ip:192.168.136.100 一.核对linux的ip ...