博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1228 稳定凸包
阅读量:6407 次
发布时间:2019-06-23

本文共 4166 字,大约阅读时间需要 13 分钟。

Grandpa's Estate
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 12337   Accepted: 3451

Description

Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa's belongings. The most valuable one was a piece of convex polygon shaped farm in the grandpa's birth village. The farm was originally separated from the neighboring farms by a thick rope hooked to some spikes (big nails) placed on the boundary of the polygon. But, when Kamran went to visit his farm, he noticed that the rope and some spikes are missing. Your task is to write a program to help Kamran decide whether the boundary of his farm can be exactly determined only by the remaining spikes.

Input

The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains an integer n (1 <= n <= 1000) which is the number of remaining spikes. Next, there are n lines, one line per spike, each containing a pair of integers which are x and y coordinates of the spike.

Output

There should be one output line per test case containing YES or NO depending on whether the boundary of the farm can be uniquely determined from the input.

Sample Input

16 0 01 23 42 02 4 5 0

Sample Output

NO
/*poj 1228 稳定凸包给你n个节点构成一个凸包,问再添加节点是否能够形成新的凸包比如: 这个点构成正方形可以看成一个不稳定凸包 ___               ___|   |     -->     /   ||___|     -->     \___|当一条边上有3个或者以上的点时,无论你怎么添加都无法改变的当逆时针旋转的时候,凸包可以看成 每次只能左转或者直走构成的一个图形当3个点一条线时,如果添加在凸包外面,那么它必需右转才可能经过那个点所以我能需要求出凸包然后判断它们是否每条边上都有3个点即可一个不错的图解:http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.htmlhhh-2016-05-07 22:17:34*/#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define lson (i<<1)#define rson ((i<<1)|1)typedef long long ll;using namespace std;const int maxn = 1010;double PI = 3.1415926;double eps = 1e-8;int sgn(double x){ if(fabs(x) < eps) return 0; if(x < 0) return -1; else return 1;}struct Point{ double x,y; Point() {} Point(double _x,double _y) { x = _x,y = _y; } Point operator -(const Point &b)const { return Point(x-b.x,y-b.y); } double operator ^(const Point &b)const { return x*b.y-y*b.x; } double operator *(const Point &b)const { return x*b.x + y*b.y; }};struct Line{ Point s,t; Line() {} Line(Point _s,Point _t) { s = _s; t = _t; } pair
operator &(const Line&b)const { Point res = s; if( sgn((s-t) ^ (b.s-b.t)) == 0) //通过叉积判断 { if( sgn((s-b.t) ^ (b.s-b.t)) == 0) return make_pair(0,res); else return make_pair(1,res); } double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t)); res.x += (t.x-s.x)*ta; res.y += (t.y-s.y)*ta; return make_pair(2,res); }};Point lis[maxn];int Stack[maxn],top;double dist(Point a,Point b){ return sqrt((a-b)*(a-b));}bool cmp(Point a,Point b){ double t = (a-lis[0])^(b-lis[0]); if(sgn(t) == 0) { return dist(a,lis[0]) <= dist(b,lis[0]); } if(sgn(t) < 0) return false; else return true;}bool Cross(Point a,Point b,Point c){ return (b.y-a.y)*(c.x-b.x) == (c.y-b.y)*(b.x-a.x);}void Graham(int n){ Point p; int k = 0; p = lis[0]; for(int i = 1; i < n; i++) { if(p.y > lis[i].y || (p.y == lis[i].y && p.x > lis[i].x)) p = lis[i],k = i; } swap(lis[0],lis[k]); sort(lis+1,lis+n,cmp); if(n == 1) { top = 1; Stack[0] = 0; return ; } if(n == 2) { Stack[0] = 0,Stack[1] = 1; top = 2; return; } Stack[0] = 0; Stack[1] = 1; top = 2; for(int i = 2; i < n; i++) { while(top > 1 && sgn((lis[Stack[top-1]]-lis[Stack[top-2]]) ^ (lis[i]-lis[Stack[top-2]])) < 0) top --; Stack[top++] = i; }}int main(){ //freopen("in.txt","r",stdin); int n,T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%lf%lf",&lis[i].x,&lis[i].y); } if(n < 6) { printf("NO\n"); continue; } Graham(n); int flag = 1; for(int i = 1;i < top-1;i++) { if(Cross(lis[Stack[i-1]],lis[Stack[i]],lis[Stack[i+1]]) == 0 && Cross(lis[Stack[i]],lis[Stack[i+1]],lis[Stack[i+2]]) == 0) { flag = 0; break; } } if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}

  

转载于:https://www.cnblogs.com/Przz/p/5510378.html

你可能感兴趣的文章
【概率论与数理统计】小结9-3 - 区间估计
查看>>
Golang性能调优入门
查看>>
sqlloader外部表
查看>>
golang笔记——数组与切片
查看>>
屏蔽可忽略的js脚本错误
查看>>
散文分享
查看>>
【Vue】vue.js常用指令
查看>>
NFS学习
查看>>
MySql常用命令总结
查看>>
又一年...
查看>>
文件上传框的美化+预览+ajax
查看>>
Linux VFS
查看>>
ext不能选中复制属性_如何实现Extjs的grid单元格只让选择(即可以复制单元格内容)但是不让修改?...
查看>>
python中print的作用*8、不能+8_在 Python 3.x 中语句 print(*[1,2,3]) 不能正确执行。 (1.0分)_学小易找答案...
查看>>
python 生成html代码_使用Python Markdown 生成 html
查看>>
axure如何导出原件_Axure 教程:轻松导出图标字体所有图标
查看>>
laravel input值必须不等于0_框架不提供,动手造一个:Laravel表单验证自定义用法...
查看>>
cad填充图案乱理石_太快了吧!原来大神是这样用CAD图案填充的
查看>>
activator.createinstance 需要垃圾回收么_在垃圾回收器中有哪几种判断是否需要被回收的方法...
查看>>
rocketmq 消息指定_RocketMQ入坑系列(一)角色介绍及基本使用
查看>>