[POJ 1228] Grandpa's Estate · 凸包
来源:互联网 发布:gps偏离路线报警算法 编辑:程序博客网 时间:2024/05/07 15:06
题目大意:给出一些点,保证是一个凸包上的顶点或边上的点,问这个凸包是否是唯一确定的,即是否能在凸包外再添加一点使得凸包变得更大。
思路:首先可以确定,对于凸包上的两个顶点,如果这两个点的连边上没有点的话,那么我们可以加一个点使得凸包变得更大
那么我们只要确定是否每两个相邻的顶点的边上是否已经有点就可以了。
判断方法:首先,对于三点i,i+1,i+2,如果向量<i,i+1>和<i,i+2>的叉积为0,则这三点共线。
对于已知的凸包上的点i,i+1,i+2,i+3,如果满足{i,i+1,i+2}和{i+1,i+2,i+3}都不能三点共线的话,那么i+1和i+2一定是凸包的两个顶点,即这两个点之间的边上是没有点的,这时就可以直接退出了。
另外有两种特殊情况:
1)所有的点都在同一条直线上,这时应输出NO
2)点数<=5,则这时不可能构成唯一确定的凸包,直接NO
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>using namespace std;const int N=1005;struct arr{int x,y;}a[N];bool cmp(const arr A,const arr B){return A.x<B.x || A.x==B.x && A.y<B.y;}bool f[N];int n,T,stack[N],top;int cross(int x,int y,int z){int x1,x2,y1,y2;x1=a[x].x-a[y].x;y1=a[x].y-a[y].y;x2=a[x].x-a[z].x;y2=a[x].y-a[z].y;return x1*y2-x2*y1;}void ConvexHull(){stack[top=1]=1;for (int i=2;i<=n;i++){while (top>1 && cross(stack[top-1],stack[top],i)>0) top--;stack[++top]=i;}int tmp=top;for (int i=n-1;i>=1;i--){while (top>tmp && cross(stack[top-1],stack[top],i)>0) top--;stack[++top]=i;}}bool judge(){bool all=1;//判断点是否全部在一条直线上 stack[top+1]=stack[1];stack[top+2]=stack[2];stack[top+3]=stack[3];for (int i=1;i<=top;i++)if (cross(stack[i],stack[i+1],stack[i+2])) {all=0;break;}if (all) return 0;for (int i=1;i<=top;i++)if (cross(stack[i],stack[i+1],stack[i+2]) && cross(stack[i+1],stack[i+2],stack[i+3]))return 0;return 1;}int main(){scanf("%d",&T);while (T--){scanf("%d",&n);for (int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);if (n<6){puts("NO");continue;}sort(a+1,a+n+1,cmp);ConvexHull();puts(judge()?"YES":"NO");}return 0;}
0 0
- poj 1228 Grandpa's Estate(凸包)
- POJ 1228 Grandpa's Estate(凸包)
- POJ 1228 Grandpa's Estate(凸包)
- poj 1228 Grandpa's Estate(凸包)
- [POJ 1228] Grandpa's Estate · 凸包
- poj 1228 Grandpa's Estate(凸包边上的点数)
- POJ 1228 Grandpa's Estate 【计算几何:凸包,andrew】
- POJ 1228 Grandpa's Estate【稳定凸包判断】
- poj 1228 Grandpa's Estate 凸包模板题
- poj 1228 Grandpa's Estate[稳定凸包]
- POJ 1228 Grandpa's Estate (稳定凸包)
- POJ 1228 || Grandpa's Estate(凸包andrew算法
- POJ 1228 Grandpa's Estate (凸包)
- POJ 1228 Grandpa's Estate(判断是否稳定凸包)
- POJ 1228 Grandpa's Estate(确定凸包)
- 【凸包性质】 POJ 1228 Grandpa's Estate
- POJ 1228:Grandpa's Estate (稳定凸包)
- poj 1228 Grandpa's Estate (凸包)
- 训练深度模型的优化问题(十一)
- 方法论之学习
- 读书《稀缺》- 今天很忙,忙过去,忙现在,忙未来?
- Python表数据统计处理程序一枚
- 如何改变<input type=”text" >输入框内的值
- [POJ 1228] Grandpa's Estate · 凸包
- 使用vs自带的dumpbin工具来查看dll、lib、或EXE文件
- OC中NSValue和NSNumber基本用法
- 冒泡法和选择法
- [MD]模仿百度手机助手动态折线图
- (ios开发)导出tableView数据至excel
- 谷歌电子市场学习笔记第五天
- NTP 服务器的安装与设定
- c语言之数组长度计算