传送门

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

题意:给你一个凸多变形,判断它是否稳定的凸包

稳定凸包:

比如有4个点:

这四个点是某个凸包上的部分点,他们连起来后确实还是一个凸包。
但是原始的凸包可能不是这样。比如:

即这四个点构成的凸包不算做“稳定”的。我们发现,当凸包上存在一条边上的点只有端点两个点的时候,这个凸包不是稳定的,因为它可以在这条边外再引入一个点,构成一个新的凸包。但一旦一条边上存在三个点,那么不可能再找到一个点使它扩展成一个新的凸包,否则构成的新多边形将是凹的。
下面是一个典型的稳定凸包:

判断是否稳定凸包的方法:
求出给定这堆点的新的凸包,然后判断凸包上的每条边上是否至少有3个点存在,假如有一条边不符合条件,那么就不是稳定凸包。

(关于稳定凸包的解释转自https://www.jianshu.com/p/1d056ac1c881)

题解:就是判断该凸变形的每一条边上是否含有三个以上所给出的点

给一组简单样例:

1
9
0 0
2 0
4 0
4 2
4 4
1 1
2 2
2 1
3 2YES

附上AC代码:

//#include"bits/stdc++.h"
//#include<unordered_map>
//#include<unordered_set>
#include<iostream>
//#include<sstream>
#include<iterator>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<bitset>
#include<climits>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<map>
#include<ctime>
#include<new>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define MT(a,b) memset(a,b,sizeof(a))
#define lson l, mid, node<<1
#define rson mid + 1, r, node<<1|1
const int INF  =  0x3f3f3f3f;
const int O    =  1e6;
const int mod  =  10007;
const int maxn =  2e3 + 5;
const double PI  =  acos(-1.0);
const double E   =  2.718281828459;
const double esp = 1e-7;struct Point { double x, y; };// 向量基本模板
typedef Point Vector;//Vector operator + (Vector a, Vector b) { return { a.x + b.x, a.y + b.y }; }
Vector operator - (Vector a, Vector b) { return { a.x - b.x, a.y - b.y }; }
//Vector operator * (Vector a, double p) { return { a.x * p, a.y * p}; }
//Vector operator / (Vector a, double p) { return { a.x / p, a.y / p}; }
//
//bool operator < (Vector a, Vector b) { return a.x * a.x + a.y * a.y < b.x * b.x + b.y * b.y; }
//bool operator == (Vector a, Vector b) { return fabs(a.x - b.x) < esp && fabs(a.y - b.y) < esp; }// 点积,模长,角度,叉积,三角形面积,逆时针旋转
//double Dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
//double Length(Vector a) { return sqrt( Dot(a, a) ); }
//double Angle(Vector a, Vector b) { return acos(Dot(a, b) / Length(a) / Length(b)); }
double Cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } // 大于0时,b在a的逆时针方向
double Area(Point A, Point B, Point C) { return Cross(B - A, C - A) / 2; } // 三角形面积叉乘公式
//Vector Rotate (Vector a, double rad) { return { a.x*cos(rad) - a.y*sin(rad), a.x*sin(rad) + a.y*cos(rad) }; }
//int dcmp(double x) { if(fabs(x) < esp) return 0; else return x < 0 ? -1 : 1; } // 精准判断正负号// 凸包模板
bool com(Point A, Point B){ return (fabs(A.x - B.x) < esp && A.y < B.y) || A.x < B.x; }
int ConvexHull(Point *P, int n, Point *A){ // P为点集合, A为凸包点(包括边上的点)sort(P, P + n, com);int m = 0;for(int i=0; i<n; i++) {while(m > 1 && Cross(A[m-1] - A[m-2], P[i] - A[m-2]) < 0) m --;A[m++] = P[i];}int k = m;for(int i=n-2; i>=0; i--){while(m > k && Cross(A[m-1] - A[m-2], P[i] - A[m-2]) < 0) m --;A[m++] = P[i];}if(n > 1) m -- ;return m;
}int main(){int T; scanf("%d", &T);while( T --) {int n; scanf("%d", &n);Point P[maxn]; for(int i=0; i<n; i++) scanf("%lf%lf", &P[i].x, &P[i].y);Point A[maxn]; int k = ConvexHull(P, n, A); // A 为凸包点bool flag = true;for(int i=0; i<k; i++) {Point p1 = A[(i+k-1) % k];Point p2 = A[i];Point p3 = A[(i+k+1) % k];Point p4 = A[(i+k+2) % k];if(Area(p1, p2, p3) != 0) // 判断p2是否顶点if(Area(p2, p3, p4) != 0) flag = false;  // 如果p2是顶点判断p2,p3,p4是否共线}if(k < 6) flag = false; // 形成稳定凸包至少存在6个点printf(flag ?  "YES\n":"NO\n");}return 0;
}

Grandpa's Estate (凸包)相关推荐

  1. POJ 1228 Grandpa's Estate --深入理解凸包

    题意: 判断凸包是否稳定. 解法: 稳定凸包每条边上至少有三个点. 这题就在于求凸包的细节了,求凸包有两种算法: 1.基于水平序的Andrew算法 2.基于极角序的Graham算法 两种算法都有一个类 ...

  2. poj 1228 Grandpa's Estate 给定了一个凸包的部分顶点和边上的点,判断是否能唯一确定一个凸包...

    题目来源: http://poj.org/problem?id=1228 题意:题目输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否唯一.所谓唯一就是判断能 ...

  3. Grandpa's Estate POJ - 1228(凸包极角序改写)

    看了题目意思之后感觉哇,简单的 一批不就是判断线段之间有没有至少一个点嘛,,,,,结果wa到自闭,, 这个题的点有首先要根据点构造凸包,因为题目给的数据不一定是一个凸包,其次,我们在构造凸包极角排序的 ...

  4. poj 1228 Grandpa's Estate

    题目衔接:http://poj.org/problem?id=1228 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 168 ...

  5. POJ1228 Grandpa's Estate

    题目: http://poj.org/problem?id=1228 题意: 给一堆点,是原凸包边上的点或内部的点(内部的点表明凸包被切割): 问能这些点能否唯一确定原来这个凸包 分析: 这是一个稳定 ...

  6. zoj 1377 Grandpa‘s Estate

    Graham算法求凸包问题 #include <iostream> #include<algorithm> using namespace std; const int max ...

  7. POJ1228(稳定凸包问题)

    题目:Grandpa's Estate   题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...

  8. POJ 1228 —— “稳定”凸包

    POJ 1228 Grandpa's Estate 这是个好题目,同时也是个不和谐的题目(不和谐原因是题目出的存在漏洞,数据弱,而且有些条件没给清楚,为了一个SB错误无限WA之后,终于AC) 题意就废 ...

  9. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

最新文章

  1. mysql 取一行_MySql – 如何获取上一行中的值和下一行中的值?
  2. android 弹出PopupWindow后背景逐渐变暗
  3. [UE4]需要保存的数据
  4. Python编程常见出错信息及原因分析(5):安装扩展库
  5. Docker学习总结(67)—— 取代 Dockerfile 的新型镜像构建技术 Buildpacks 详解
  6. AndroidStudio_开发工具的设置_代码编辑器使用_新特性---Android原生开发工作笔记73
  7. Python3 解释器
  8. 初探image-set及如何适配移动端高清屏图片
  9. Python 下的 lambda 算子
  10. CSS实现文字半透明显示在图片上方法
  11. Linux wget下载方式
  12. Maya动画后期——粒子特效的制作
  13. 3709: [PA2014]Bohater
  14. Oracle HFM OHS服务无法启动
  15. 洛谷P5149 会议座位
  16. 超级实时图形计算机,HyperCalc Graphing Calculator(超级图形计算器)
  17. 【RF预测】基于matlab随机森林算法数据回归预测【含Matlab源码 2047期】
  18. cv曲线面积的意义_耳机的瀑布图真的有意义吗?关于耳机的瀑布图,你需要知道的。...
  19. 计算机怎样将多行文字转换成表格,用WPS文本表格转换快速合并多行文字
  20. CSP认证:棋局评估

热门文章

  1. 孤岛惊魂4服务器稳定吗,《孤岛惊魂5》PC性能综合测试 程序运行稳定、改进完爆前作...
  2. 仓库管理系统软件哪个好
  3. 华为p20nfc怎么复制门禁卡_EMUI的这个功能,让手机瞬间化身门禁卡
  4. flickr30k图像标注数据集下载地址
  5. PHP 面试踩过的坑
  6. 计算机R5,IT教程:电脑r5和r7是什么意思
  7. R语言reshape包加载出现环境参数错误的解决方式
  8. 视频教程-手把手实现Java图书管理系统(附源码)-Java
  9. 信用卡,今天你办了吗?
  10. adminLTE 教程