poj3335 半交平面,多边形内核
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 5300 | Accepted: 2112 |
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
Source
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define exp 1e-10 struct node
{
double x;
double y;
}; node point[];//记录最开始的多边形
node q[]; //临时保存新切割的多边形
node p[]; //保存新切割出的多边形
int n,m;//n的原先的点数,m是新切割出的多边形的点数
double a,b,c; void getline(node x,node y) //获取直线ax+by+c==0
{
a=y.y-x.y;
b=x.x-y.x;
c=y.x*x.y-x.x*y.y;
} node intersect(node x,node y) //获取直线ax+by+c==0 和点x和y所连直线的交点
{
double u=fabs(a*x.x+b*x.y+c);
double v=fabs(a*y.x+b*y.y+c);
node ans;
ans.x=(x.x*v+y.x*u)/(u+v);
ans.y=(x.y*v+y.y*u)/(u+v);
return ans;
} void cut() //用直线ax+by+c==0切割多边形
{
int cutm=,i;
for(i=;i<=m;i++)
{
if(a*p[i].x+b*p[i].y+c>=) //题目是顺时钟给出点的
{ //所以一个点在直线右边的话,那么带入值就会大于等于0
q[++cutm]=p[i]; //说明这个点还在切割后的多边形内,将其保留
}
else
{
if(a*p[i-].x+b*p[i-].y+c>) //该点不在多边形内,但是它和它相邻的点构成直线与
{ //ax+by+c==0所构成的交点可能在新切割出的多边形内,
q[++cutm]=intersect(p[i-],p[i]); //所以保留交点
}
if(a*p[i+].x+b*p[i+].y+c>)
{
q[++cutm]=intersect(p[i+],p[i]);
}
}
}
for(i=;i<=cutm;i++)
{
p[i]=q[i];
}
p[cutm+]=q[];
p[]=q[cutm];
m=cutm;
} void solve()
{
int i;
for(i=;i<=n;i++)
{
p[i]=point[i];
}
point[n+]=point[];
p[n+]=p[];
p[]=p[n];
m=n;
for(i=;i<=n;i++)
{
getline(point[i],point[i+]); //根据point[i]和point[i+1]确定直线ax+by+c==0
cut(); //用直线ax+by+c==0切割多边形
}
} int main()
{
int cas,i;
//freopen("D:\\in.txt","r",stdin);
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%lf%lf",&point[i].x,&point[i].y);
}
solve();
if(m==)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return ;
}
poj3335 半交平面,多边形内核的更多相关文章
- bzoj 1007 半交平面简化版
本题就是求半交平面的交包含哪些直线,而且有点特殊(一般的半交平面用双端队列,因为可能转到最开始的直线,但本题不会,所以只需要一端操作就行了). /*************************** ...
- 计算几何-多边形内核判定-HPI-poj3335
This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 先解决一个问题, ...
- poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】
<题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...
- Rotating Scoreboard - POJ 3335(半面相交求多边形内核)
题目大意:RT 分析:所谓内核可以理解为在多边形内存在点可以在这个点上看到多边形内部所有的部分,当然怎么求出来就是问题的关键了.我们知道多边形的每条边都是边界值,边的左边和右边肯定是一部分属于多边形一 ...
- poj3335 半平面交
题意:给出一多边形.判断多边形是否存在一点,使得多边形边界上的所有点都能看见该点. sol:在纸上随手画画就可以找出规律:按逆时针顺序连接所有点.然后找出这些line的半平面交. 题中给出的点已经按顺 ...
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...
- POJ 3335 Rotating Scoreboard(半平面交求多边形核)
题目链接 题意 : 给你一个多边形,问你在多边形内部是否存在这样的点,使得这个点能够看到任何在多边形边界上的点. 思路 : 半平面交求多边形内核. 半平面交资料 关于求多边形内核的算法 什么是多边形的 ...
- 【kuangbin专题】计算几何_半平面交
1.poj3335 Rotating Scoreboard 传送:http://poj.org/problem?id=3335 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的 ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
随机推荐
- Mysql: ERROR 1030 (HY000): Got error 28 from storage engine
今天帮同事解决一个问题的时候,遇到了下面的异常: ERROR 1030 (HY000): Got error 28 from storage engine 我们的数据库是mysql,我们的sql语句是 ...
- Aspx生命周期
今天去面试,碰到面试官问这个问题.aspx页面生命周期是什么?顿时懵逼 还跟我解释:就是页面怎么解析的aspx页面.果断没看过这方面知识,没答上来.现在记录一下 ASP.NET页面生命周期 ASP.N ...
- 在Ubuntu上如何往fcitx里添加输入法
Ubuntu 16.04引入了一个新的包管理工具apt, 用法与apt-get类似. 在终端用apt搜索fcitx支持的输入法 apt search fcitx All Fcitx related p ...
- rpm包安装过程中依赖问题“libc.so.6 is needed by XXX”解决方法
rpm包安装过程中依赖问题"libc.so.6 is needed by XXX"解决方法 折腾了几天,终于搞定了CentOS上的Canon LBP2900打印机驱动.中间遇到了一 ...
- C++ Virtual
摘自:http://www.cnblogs.com/xd502djj/archive/2010/09/22/1832912.html namespace QCAR { /// Area is the ...
- 捉襟见肘之自定义自拍相机AVFoundation
因为上篇的问题的,我搜索到解决方法: http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-ima ...
- SaltStack之无Master和多Master(九)
SaltStack之无Master和多Master Masterless架构,无Master 实现方式: 1)关闭minion进程 2)修改配置文件 vi /etc/salt/minion file_ ...
- 利用百度开发者中心的api实现地图及周边的搜索
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- Linux下显示IP地理位置信息的小工具-nali
一.简介 nali,名字取自中文“哪里”的拼音.nali包含一组命令行程序,其主要功能就是把一些网络工具的输出的IP字符串,附加上地理位置信息(使用纯真数据库QQWry.Dat).例如74.125.1 ...
- 最大似然估计 (MLE) 最大后验概率(MAP)
1) 最大似然估计 MLE 给定一堆数据,假如我们知道它是从某一种分布中随机取出来的,可是我们并不知道这个分布具体的参,即"模型已定,参数未知". 例如,我们知道这个分布是正态分布 ...