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个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
随机推荐
- 帝国CMS文章随机调用等一些常用标签
1.帝国CMS文章随机调用等一些常用标签 [e:loop={'news',10,18,0,'newstime>UNIX_TIMESTAMP()-86400*7','onclick desc'}] ...
- hibernate-criteria查询
Criteria查询是Hibernate提供的一种查询方式 下面就一个员工和部门来列一个总体的例子 package Test; import java.util.ArrayList; import j ...
- 超强语感训练文章(Provided by Rocky teacher Prince)
Content: Class1 My name is Prince Class2 Welcome to our hotel Class3 We’re not afraid of problems Cl ...
- CF721C. Journey
传送门 说实话,这是一道非常简单的DP题,简单到如果放到NOIp第二题可能都有些差强人意,然而我写崩了. 所以简单记录一下. 需要注意的是,这道题的DP应该是从$N$点开始,以1为边界,满足最短路的三 ...
- mac OS(OS X)的OI编译环境配置指南
编译环境:gdb+Atom 如何安装gdb: http://logic0.blog.163.com/blog/static/1889281462014183271283/ Atom下载地址: ht ...
- hibernate......1、2级缓存
1.什么是缓存? 缓存是介于物理数据源与应用程序之间,是对数据库中的数据复制一份临时放在内存中的容器,其作用是为了减少应用程序对物理数据源访问的次数,从而提高了应用程序的运行性能.Hibernate在 ...
- HTTPS背后的加密算法
当你在浏览器的地址栏上输入https开头的网址后,浏览器和服务器之间会在接下来的几百毫秒内进行大量的通信.InfoQ的这篇文章对此有非常详细的描述.这些复杂的步骤的第一步,就是浏览器与服务器之间协商一 ...
- css012 css布局简介
css012 css布局简介 一. 网页布局的类型 网页布局的类型 1.固定宽度 2.流式 3.相应式web设计 二. 如何进行css布局 1.强大的<div>标签 网页的h ...
- beautifulsoup测试
import re from bs4 import BeautifulSoup html_doc = """ <html><head><ti ...
- cmd chcp命令切换字符格式UTF8
cmd chcp命令切换字符格式 命令介绍: chcp 65001 #换成utf-8代码页 chcp 936 #换成默认的gbk chcp 437 #美国英 ...