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

1
6
0 0
1 2
3 4
2 0
2 4
5 0

Sample Output

NO

题意:给定一些点,问是否可以确定一个凸包。

思路:求出凸包后,每条边上若至少有3个点,则可以确定。

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
const double pi=acos(-1.0);
const double eps=1e-;
struct Cpoint
{
double x,y;
Cpoint(){}
Cpoint(double xx,double yy):x(xx),y(yy){}
Cpoint friend operator -(Cpoint a,Cpoint b){
return Cpoint(a.x-b.x, a.y-b.y);
}
double friend operator ^(Cpoint a,Cpoint b){
return a.x*b.y-b.x*a.y;
}
bool friend operator <(Cpoint a,Cpoint b){
if(a.y==b.y) return a.x<b.x;
return a.y<b.y;
}
};
double dist(Cpoint a,Cpoint b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int Sign(double x)
{
if(x>=-eps&&x<=eps) return ;
if(x>eps) return ; return -;
}
int N; Cpoint P[maxn];
bool cmp(Cpoint a,Cpoint b)
{
int s=Sign((a-P[])^(b-P[]));
if(s>||(s==&&dist(a,P[])<dist(b,P[]))) return true;
return false;
}
int find(Cpoint a,Cpoint b)
{
int res=;
for(int i=;i<=N;i++){
if(Sign((P[i].x-a.x)*(P[i].x-b.x))>) continue;
if(Sign((P[i].y-a.y)*(P[i].y-b.y))>) continue;
if(Sign((b-a)^(P[i]-a))==) res++;
}
return res;
}
bool Graham()
{
if(N<) return false;//肯定不构成凸包
sort(P+,P+N+); //得到“原点 ”
sort(P+,P+N+,cmp); //得到积角序
int q[maxn],top=;
q[]=; q[]=; //q[3]=3;
for(int i=;i<=N;i++){
while(top>&&Sign((P[q[top]]-P[q[top-]])^(P[i]-P[q[top]]))<=) top--;
q[++top]=i;
}
if(top<) return false; //不构成凸包
for(int i=;i<top;i++) if(find(P[q[i]],P[q[i+]])<) return false;
if(find(P[q[top]],P[q[]])<) return false;
return true;
}
int main()
{
int T;scanf("%d",&T);
while(T--){
scanf("%d",&N);
for(int i=;i<=N;i++)
scanf("%lf%lf",&P[i].x,&P[i].y);
if(Graham()) printf("YES\n");
else printf("NO\n");
}return ;
}

POJ1228:Grandpa's Estate(给定一些点,问是否可以确定一个凸包)的更多相关文章

  1. POJ1228 Grandpa's Estate 稳定凸包

    POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html   这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...

  2. poj1228 Grandpa's Estate

    地址:http://poj.org/problem?id=1228 题目: Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  3. POJ1228:Grandpa's Estate——题解

    http://poj.org/problem?id=1228 题目大意:给一个凸包,问是否为稳定凸包. ———————————————————————— 稳定凸包的概念为:我任意添加一个点都不能使这个 ...

  4. POJ 1228 Grandpa's Estate(凸包)

    Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11289   Accepted: 3117 ...

  5. 【POJ】1228 Grandpa's Estate(凸包)

    http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...

  6. POJ 1228 Grandpa's Estate 凸包 唯一性

    LINK 题意:给出一个点集,问能否够构成一个稳定凸包,即加入新点后仍然不变. 思路:对凸包的唯一性判断,对任意边判断是否存在三点及三点以上共线,如果有边不满足条件则NO,注意使用水平序,这样一来共线 ...

  7. 平面上给定n条线段,找出一个点,使这个点到这n条线段的距离和最小。

    题目:平面上给定n条线段,找出一个点,使这个点到这n条线段的距离和最小. 源码如下: #include <iostream> #include <string.h> #incl ...

  8. 【IT笔试面试题整理】给定二叉树,给每层生成一个链表

    [试题描述]定义一个函数,给定二叉树,给每层生成一个链表 We can do a simple level by level traversal of the tree, with a slight ...

  9. 语义分割(semantic segmentation) 常用神经网络介绍对比-FCN SegNet U-net DeconvNet,语义分割,简单来说就是给定一张图片,对图片中的每一个像素点进行分类;目标检测只有两类,目标和非目标,就是在一张图片中找到并用box标注出所有的目标.

    from:https://blog.csdn.net/u012931582/article/details/70314859 2017年04月21日 14:54:10 阅读数:4369 前言 在这里, ...

随机推荐

  1. Android UI自定义Spinner下拉框(用popuwindow实现)-转

    定义出第一个图片的布局和弹出框(一个listView)的布局,,这里就不在多说了~ListView需要自己定义一个MyspinnerAdapter~做好这些准备之后,就是弹出框的实现了~  prote ...

  2. POJ 2396 有源有汇有上下界可行流问题

    题意:给一个矩阵,给出每行每列之和,附加一些条件,如第i行第j列数必需大于(小于)多少. 思路题解:矩阵模型,模拟网络流,行.列标号为结点,构图,附加s,t,s连行标(容量上下限每行之和(必需以这个 ...

  3. HDU 5676 ztr loves lucky numbers【DFS】

    题目链接; http://acm.hdu.edu.cn/showproblem.php?pid=5676 题意: 由4和7组成的且4和7出现次数相同的数称为幸运数字,给定n,求不大于n的最大幸运数字. ...

  4. java中简单内存计算

    今天面试遇到一个问题,假设一个类中只声明一个int类型,那么这个对象多大,这里先写出解决方案,首先引入内存计算工具lucene-core, <dependency> <groupId ...

  5. 优秀的数据序列和还原类----TSimpleMsgPack

    优秀的数据序列和还原类----TSimpleMsgPack TSimpleMsgPack是D10天地弦的作品. 优点:至简,就一个单元文件实现,不需要引用其他单元. 缺点:不是标准的MSGPACK实现 ...

  6. docker日志输出文件大小设置以及文件个数限制

    问题描述: 今天有同事运行了一个docker容器,不多时就导致宿主机硬盘直接撑爆,消耗了120G,发生的很是突然. 问题排查: 后续查阅资料,发现是因为docker中的某个进程一直在持续输出,而这些输 ...

  7. ubuntu uninstall postgres

    Steps that worked for me on Ubuntu 8.04.2 to remove postgres 8.3 List All Postgres related packages ...

  8. svn 创建分支、切换分支 及 合并分支 操作

    关联远程仓库: 右键  ---  点击 ' SVN Checkout...' 生成 打开trunk目录,在trunk目录下新建两个文本文件A.java,B.java: 打开A.java输入以下内容: ...

  9. Android中怎样自己制作su

    本文原博客:http://hubingforever.blog.163.com/blog/static/171040579201372915716149/ 在Android源代码的system\ext ...

  10. TCP连接建立与终止,及状态转换

    TCP连接建立 三路握手 三路握手发生在客户端发起connect请求到服务端accept返回中,在三路握手发生前,服务端必须准备好接受外来连接,这通常通过服务端调用 (socket.bind.list ...