链接: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 ;
}

poj 3335(半平面交)的更多相关文章

  1. poj 1755 半平面交+不等式

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6461   Accepted: 1643 Descrip ...

  2. poj 1279 半平面交核面积

    Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6668   Accepted: 2725 Descr ...

  3. poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积

    /*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...

  4. poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】

    <题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...

  5. POJ 3525 /// 半平面交 模板

    题目大意: 给定n,接下来n行逆时针给定小岛的n个顶点 输出岛内离海最远的点与海的距离 半平面交模板题 将整个小岛视为由许多半平面围成 那么以相同的比例缩小这些半平面 一直到缩小到一个点时 那个点就是 ...

  6. POJ 3525 半平面交+二分

    二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点 #include <cstdio> #include <cstring> # ...

  7. POJ 3335 Rotating Scoreboard 半平面交求核

    LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...

  8. poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 25 ...

  9. 三道半平面交测模板题 Poj1474 Poj 3335 Poj 3130

    求半平面交的算法是zzy大神的排序增量法. ///Poj 1474 #include <cmath> #include <algorithm> #include <cst ...

随机推荐

  1. android 百度地图定位开发2

    先下载了示例代码 进行配置(可查看开发 指南 Hello BaiDuMap) 第一步:创建并配置工程(具体方法参见工程配置部分的介绍): 第二步:在AndroidManifest中添加开发密钥.所需权 ...

  2. Android侧滑

    人人客户端有一个特效还是挺吸引人的,在主界面手指向右滑动,就可以将菜单展示出来,而主界面会被隐藏大部分,但是仍有左侧的一小部分同菜单一起展示. 据说人人客户端的这个特效是从facebook客户端模仿来 ...

  3. linux下串口控制

    /*  本程序符合GPL条约  *  Beneboy 2003-5-16 */ #include <stdio.h>              // printf #include < ...

  4. mongodb数据库实践笔记

    mongodb 操作规则 从网站上下载安装文件然后在安装目录下创建文件夹data和log创建配置文件mongo.config里面填充如下: ##数据文件dbpath=D:\mongodb\data## ...

  5. UIScrollView的滚动位置设置

    1.如果手动设置滚动异常,可以从最小值到最大值,极限调试.最小值取一个,中间值取n个,最大值取一个.

  6. Android使用Application总结

    对于application的使用,一般是 在Android源码中对他的描述是; * Base class for those who need to maintain global applicati ...

  7. <mvc:annotation-driven />与<context:annotation-config />

    Spring家族的配置中这两个配置的意义,说具体点其实根据标签的shecma就能看出来,mvc,主要就是为了Spring MVC来用的,提供Controller请求转发,json自动转换等功能,而co ...

  8. Linux下后台程序完成自动输入密码等交互行为的例子

    今天要开发一个定时任务,然后加入cron列表中.但是有个问题摆在眼前,脚本的执行中需要输入数据库密码: mysql -u root -p << SQL use db; set names  ...

  9. Install Hive

    一.Hive将元数据存储在RDBMS中,有三种模式可以连接到数据: 1.single User Mode:此模式连接到一个In-memory的数据库Derby,一般用于Unit Test. 2.Mul ...

  10. 4、BOM编程/正则表达式

    1.    BOM编程 1.1. BOM编程基础 全称 Browser Object Model,浏览器对象模型. JavaScript是由浏览器中内置的javascript脚本解释器程序来执行jav ...