链接:http://poj.org/problem?id=3335     //大牛们常说的测模板题

----------------------------------------------------------------

Rotating Scoreboard
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

 
 
 
-----------------------------------------------------------------------------------
看了N久,感觉好难
分别看了这里:http://blog.csdn.net/dream_ysl/article/details/7831293
           这里:http://blog.csdn.net/zxy_snow/article/details/6596237
           这里:http://blog.csdn.net/accry/article/details/6070621
一直引用大牛zxy_snow的模板,希望大牛别生气啊
 
个人觉得半平面交确实要花好多功夫,
一要理解N^2的是求如何出来的                       //用给定的多边形每一条边去切割它自己
二要判断给定的点是逆时针or顺时针,要加判断    //用连向原点的面积正负判断
三要理解代码,每一次切割过后的边数要更新,给下一个循环
四要自己在草稿纸上画画,一定理解了才去做题(测模板)
-----------------------------------------------------------------------------------
 
 #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 ;
}

最新文章

  1. Spartan Exploit Kit分析
  2. ElasticSearch部署安装
  3. php获取网页内容方法总结
  4. Android:Android SDK Manager顺利下载
  5. codeforces #313 div1 C
  6. linux常用命令(4)rm命令
  7. 【USACO】玉米实验(单调队列)
  8. angularjs 服务详解
  9. Python开发【第十篇】:RabbitMQ队列
  10. 基于阿里云 DNS API 实现的 DDNS 工具
  11. VSCode typescript ctrl+shift+b can&#39;t be compiled error:TS5007
  12. Python快速学习02:基本数据类型 &amp; 序列
  13. java.lang.StackOverflowError 解决方法
  14. Bootstrap3基础 page-header 标题下加分割线
  15. 多臂机测试, AB测试
  16. Linux移植之配置过程分析
  17. rtsp实现的开源代码
  18. jmeter 基础功能详解
  19. CentOS普通用户没有sudo权限
  20. 2017-2018-1 20155233 《信息安全系统设计基础》实现mypwd

热门文章

  1. Python标准库之核心模块学习记录
  2. selenium滚动条
  3. docker-gerrit
  4. 161031、java.util.StringTokenizer使用及源码
  5. ctl 里面pdef解说
  6. java中枚举类的使用详解
  7. hdu 1061 Rightmost Digit
  8. 【转】SVN服务器搭建--Subversio与TortoiseSVN的配置安装
  9. CallableAndFuture
  10. 怎么查看jar包版本