POJ 1228 凸包
来源:互联网 发布:python cuda windows 编辑:程序博客网 时间:2024/06/03 19:25
这题考察凸包的理解,题意让求一个凸包上每条边都有三个点,如果少于三个点那么凸包就不确定了,三点以上如果再加一个点就形成不了凸包了。通过极角排序完然后求跟凸包的相邻两点共线的点有没有就可以了,写得比较挫。。。
(1)此题需要判断“凸包上每条边至少包含原多边形三个点”。成立就是“YES”。 我试的判断“多边形上 所有点 在凸包上”,WA!!(2)注意:所有点共线时,结果为“NO”。(3)另外由上面(1)判断可的,n<=5时,结果为"NO"。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;typedef double PointType;struct point{ PointType x,y; int num;};point data[1005],stack[1005],MinA;int top;PointType Direction(point pi,point pj,point pk) //判断向量PiPj在向量PiPk的顺逆时针方向 +顺-逆0共线{ return (pj.x-pi.x)*(pk.y-pi.y)-(pk.x-pi.x)*(pj.y-pi.y);}PointType Dis(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}bool cmp(point a,point b){ PointType k=Direction(MinA,a,b); if(k>0) return 1; if(k<0) return 0; return Dis(MinA,a)>Dis(MinA,b);}void Graham_Scan(point *a,int numa){ for(int i=0; i<numa; i++) if(a[i].y<a[0].y||(a[i].y==a[0].y&&a[i].x<a[0].x)) swap(a[i],a[0]); MinA=a[0],top=0; sort(a+1,a+numa,cmp); stack[top++]=a[0],stack[top++]=a[1],stack[top++]=a[2]; for(int i=3; i<numa; i++) { while(Direction(stack[top-2],stack[top-1],a[i])<0) top--; stack[top++]=a[i]; }}bool judgeline(int n){ for(int i=2; i<n; i++) if(Direction(data[i-2],data[i-1],data[i])) return 0; return 1;}int main(){ int n,t,m; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0; i<n; i++) scanf("%lf%lf",&data[i].x,&data[i].y); if(n<6||judgeline(n)) { puts("NO"); continue; } Graham_Scan(data,n); int f=1; for(int i=0,j=0; i<top; i++) { int num=0; if(i<top-1) { for(int j=0; j<n; j++) if(!Direction(stack[i],stack[i+1],data[j])) num++; } else for(int j=0; j<n; j++) if(!Direction(stack[i],stack[0],data[j])) num++; if(num<3) { f=0; break; } } puts(f?"YES":"NO"); } return 0;}
- poj 1228(凸包)
- POJ 1228 凸包
- POJ 1228 凸包
- POJ 1228 (凸包)
- POJ 1228 凸包
- poj 1228 完整凸包
- POJ 1228(稳定凸包)
- POJ 1228 稳定凸包
- POJ-1228(稳定凸包)
- POJ 1873 & 1228 凸包和稳定凸包
- poj 1228 判唯一凸包
- poj 1228 Grandpa's Estate(凸包)
- POJ 1228 Grandpa's Estate(凸包)
- POJ 1228 Grandpa's Estate(凸包)
- poj 1228 Grandpa's Estate(凸包)
- POJ 1228 稳定凸包问题
- POJ 1228 (计算几何 凸包)
- poj 1228 求一个稳定凸包
- Java面试:代码题19道
- C++模板学习
- mini2440驱动分析之PWM
- Daikon的安装经验
- Oracle BBED 工具 说明
- POJ 1228 凸包
- gearman及python客户端安装和使用
- 使用git下载项目资源
- 设计模式之依赖倒转原则
- codeforces 145E - Lucky Queries
- 为什么要内存对齐 Data alignment: Straighten up and fly right
- 程序员要知道的TCP/IP知识
- MYSQL数据库转移
- 对java中的wait,notify,synchronized的总结