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 ...
随机推荐
- 关于UIView(转)
曾经有人这么说过,在iphone里你看到的,摸到的,都是UIView,所以UIView在iphone开发里具有非常重要的作用.那么UIView我们到底知道多少呢.请看看下面的问题, 如果这些你都知道, ...
- innodb的锁到底占用多少内存
举个简单的例子: CREATE TABLE `sample` ( `i` ) unsigned NOT NULL auto_increment, `j` ) default NULL, PRIMARY ...
- linux设备驱动归纳总结(八):4.总线热插拔【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-110774.html linux设备驱动归纳总结(八):4.总线热插拔 xxxxxxxxxxxxxxx ...
- 为什么很多人用keepalived来实现redis故障转移
目前,Redis还没有一个类似于MySQL Proxy或Oracle RAC的官方HA方案.Redis作者有一个名为Redis Sentinel的计划 ,据称将会有监控,报警和自动故障转移三大功能,非 ...
- SQL Server系统表sysobjects介绍与使用
关于SQL Server数据库的一切信息都保存在它的系统表格里.我怀疑你是否花过比较多的时间来检查系统表格,因为你总是忙于用户表格.但是,你可能需要偶尔做一点不同寻常的事,例如数据库所有的触发器.你可 ...
- office 2016 专业增强版 和 visio 2016 专业版 下载安装(附带激活工
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://babyshen.blog.51cto.com/8405584/1697910 o ...
- 在MyEclipse中搭建Spring MVC开发环境
环境版本 IDE:MyEclipse 8.5 Spring:spring 3.2.8 JDK:1.6 1.打开MyEclipse-->File-->New-->Web Project ...
- linux下echo命令详解(转)
linux的echo命令, 在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的, 因此有必要了解下echo的用法 echo命令的功能是在显示器上显示一段文字,一般起到一个 ...
- iOS 第一次安装应用,拒绝相机调用,页面卡死的解决方案
void (^allowBlock)() = ^{ UIImagePickerController *imagePicker = [[UIImagePickerController alloc] in ...
- linux中的nm命令简介
转:http://blog.csdn.net/stpeace/article/details/47089585 一般来说, 搞linux开发的人, 才会用到nm命令, 非开发的人, 应该用不到. 虽然 ...