poj 3335(半平面交)
链接:http://poj.org/problem?id=3335 //大牛们常说的测模板题
----------------------------------------------------------------
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5158 | Accepted: 2061 |
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 <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <iostream>
- #include <algorithm>
- #include <math.h>
- using namespace std;
- #define eps 1e-8
- #define MAXX 105
- typedef struct
- {
- double x;
- double y;
- }point;
- point p[MAXX],s[MAXX];
- bool dy(double x,double y) {return x>y+eps; }
- bool xy(double x,double y) {return x<y-eps; }
- bool dyd(double x,double y){return x>y-eps; }
- bool xyd(double x,double y){return x<y+eps; }
- bool dd(double x,double y) {return fabs(x-y)<eps; }
- double crossProduct(point a,point b,point c)
- {
- return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
- }
- point IntersectPoint(point u1,point u2,point v1,point v2)
- {
- point ans=u1;
- double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/
- ((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
- ans.x += (u2.x-u1.x)*t;
- ans.y += (u2.y-u1.y)*t;
- return ans;
- }
- void cut(point p[],point s[],int n,int &len)
- {
- point tp[MAXX];
- p[n]=p[];
- for(int i=; i<=n; i++)
- {
- tp[i]=p[i];
- }
- int cp=n,tc;
- for(int i=; i<n; i++)
- {
- tc=;
- for(int k=; k<cp; k++)
- {
- if(dyd(crossProduct(p[i],p[i+],tp[k]),0.0))
- s[tc++]=tp[k];
- if(xy(crossProduct(p[i],p[i+],tp[k])*
- crossProduct(p[i],p[i+],tp[k+]),0.0))
- s[tc++]=IntersectPoint(p[i],p[i+],tp[k],tp[k+]);
- }
- s[tc]=s[];
- for(int k=; k<=tc; k++)
- tp[k]=s[k];
- cp=tc;
- }
- len=cp;
- }
- int main()
- {
- int n,m,i,j;
- scanf("%d",&n);
- while(n--)
- {
- scanf("%d",&m);
- for(i=; i<m; i++)
- scanf("%lf%lf",&p[i].x,&p[i].y);
- int len;
- cut(p,s,m,len);
- if(len)printf("YES\n");
- else printf("NO\n");
- }
- return ;
- }
poj 3335(半平面交)的更多相关文章
- poj 1755 半平面交+不等式
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6461 Accepted: 1643 Descrip ...
- poj 1279 半平面交核面积
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6668 Accepted: 2725 Descr ...
- poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积
/*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...
- poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】
<题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...
- POJ 3525 /// 半平面交 模板
题目大意: 给定n,接下来n行逆时针给定小岛的n个顶点 输出岛内离海最远的点与海的距离 半平面交模板题 将整个小岛视为由许多半平面围成 那么以相同的比例缩小这些半平面 一直到缩小到一个点时 那个点就是 ...
- POJ 3525 半平面交+二分
二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点 #include <cstdio> #include <cstring> # ...
- POJ 3335 Rotating Scoreboard 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- poj 3335 Rotating Scoreboard(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
- 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130
求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...
随机推荐
- ImagXpress中如何修改Alpha通道方法汇总
ImagXpress支持处理Alpha通道信息来管理图像的透明度,Alpha通道支持PNG ,TARGA和TIFF文件,同时还支持BMP和ICO文件.如果说保存的图像样式不支持Alpha通道,就将会丢 ...
- PHP用substr截取字符串出现中文乱码问题用mb_substr
PHP用substr截取字符串出现中文乱码问题用mb_substr实例:mb_substr('截取中文乱码问题测试',0,5, 'utf-8'); 语法 : string substr (string ...
- Array JSON
Tool: Online jsonviewer JSON: JavaScript Object Notation. JSON is a syntax for storing and exchangin ...
- MongoDB C# / .NET Driver
MongoDB C# Driver是官方提供的.NET C#驱动. Getting Started with the C# Driver C# Driver Tutorial C# Driver LI ...
- Hadoop之回收站
一.回收站简介: 在HDFS里,删除文件时,不会真正的删除,其实是放入回收站/trash,回收站里的文件可以快速恢复. 可以设置一个时间阀值,当回收站里文件的存放时间超过这个阀值或是回收站被清空时,文 ...
- php const define 区别有那些呢?
(1) 编译器处理方式不同 define宏是在预处理阶段展开. const常量是编译运行阶段使用. (2) 类型和安全检查不同 define宏没有类型,不做任何类型检查,仅仅是展开. const常量有 ...
- Facebook MyRocks at MariaDB
Recently my colleague Rasmus Johansson announced that MariaDB is adding support for the Facebook MyR ...
- Windows下打包Python的exe可执行文件
参考:http://www.cnblogs.com/Lands-ljk/p/5447723.html
- oracle 存储过程和函数例子
关于 游标 if,for 的例子 create or replace procedure peace_if is cursor var_c is select * from grade; begin ...
- css写法优化
写css关于id,class等的命名,文件的结构,共同模块的提取,代码的复用性,可读性,扩展性,维护性都要考虑,不然后期可以会需要花大力气去进行维护修改.考虑写出足够科学的css,需要考虑下面几个方面 ...