Grandpa's Estate POJ
来源:互联网 发布:照片转十字绣软件 编辑:程序博客网 时间:2024/06/05 16:44
稳定的凸包满足:在加新点使凸包扩大时,新凸包无法包含原来的所有顶点
换句话说,一个稳定的凸包的每一条边上都有至少三个顶点
题目数据比较水,没有所有点共线的特判(非稳定),我也就懒得写了
//#include<bits/stdc++.h> //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<algorithm> #include<queue> #include<string.h> #include<iostream> #include<math.h> #include<set> #include<map> #include<vector> #include<iomanip> using namespace std; const double pi=acos(-1.0); #define ll long long #define pb push_back#define sqr(a) ((a)*(a))#define dis(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))const double eps=1e-6;const int maxn=1e3+56;const int inf=0x3f3f3f3f;int n;int tot;//凸包上点数struct Point{double x,y;Point(){}Point(double x,double y):x(x),y(y){}}point[maxn],vertex[maxn];bool cmp(Point a,Point b){return(a.y<b.y||(a.y== b.y && a.x<b.x));}double xmult(Point p1,Point p2,Point p3){//p3p1,p3p2的夹角测试return ( (p1.x-p3.x)*(p2.y-p3.y)-(p1.y-p3.y)*(p2.x-p3.x) );}//正表示p1在p2的顺时针方向int Andrew(){//返回凸包顶点数sort(point,point+n,cmp);int top=1;vertex[0]=point[0];vertex[1]=point[1];for(int i=2;i<n;i++){while(top && xmult(point[i],vertex[top],vertex[top-1])>eps)top--;vertex[++top]=point[i];}int len=top;vertex[++top]=point[n-2];for(int i=n-3;i>=0;i--){while(top!=len && xmult(point[i],vertex[top],vertex[top-1])>eps)top--;vertex[++top]=point[i];}return top;}bool judge(int n){//判凸包稳定for(int i=1;i<n;i++){if(fabs(xmult(vertex[i],vertex[i+1],vertex[i-1]))>eps&& fabs(xmult(vertex[i],vertex[i+1],vertex[(i+2)%(n)]))>eps){return 0;}}return 1;}int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%lf%lf",&point[i].x,&point[i].y);}tot=Andrew();if(tot<6){printf("NO\n");continue;}if(judge(tot))printf("YES\n");else printf("NO\n");}}
阅读全文
0 0
- poj Grandpa's Estate
- Grandpa's Estate POJ
- 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
- 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
- POJ 1228 Grandpa's Estate
- zoj 1377 || poj 1228 Grandpa's Estate
- 数据结构——复习笔记(广工版)
- 多个微服务在docker中运行,且互相调用,解决他们之间的connection问题
- 内存中的数组
- # Java实现冒泡排序—详细解析优化版冒泡
- 第四周项目2
- Grandpa's Estate POJ
- Oracle数据库之同义词(SYNONYM)使用
- 合并果子
- 第4周项目3
- 数据结构学习笔记:数组与链表的区别
- 【2017.9.26】博客貌似好久没更新了
- c++学习笔记【回顾】
- 机房收费系统之上下机
- c++基础学java知识点(类的基本语法)