poj1228 Grandpa's Estate(凸包)
2016-09-27 14:30
387 查看
poj1228
题目
给你一些肯定在凸包上的点,问这些点构成的凸包是不是稳定的凸包。思路
稳定凸包的话每条边上至少三个给定点。代码
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define pi acos (-1) #define rotate Rotate using namespace std; typedef long long ll; const double eps = 1e-8; const int maxn=1010; const double INF = 1e20; int dcmp (double x) { if (f 4000 abs (x) < eps) return 0; else return x < 0 ? -1 : 1; } struct point { double x, y; int pos; point (double _x = 0, double _y = 0,int _pos=0) : x(_x), y(_y),pos(_pos) {} point operator - (point a) const { return point (x-a.x, y-a.y); } point operator + (point a) const { return point (x+a.x, y+a.y); } bool operator < (const point &a) const { return x < a.x || (x == a.x && y < a.y); } bool operator == (const point &a) const { return dcmp (x-a.x) == 0 && dcmp (y-a.y) == 0; } }; point operator * (point a, double p) { return point (a.x*p, a.y*p); } double cross (point a, point b) { return a.x*b.y-a.y*b.x; } double dot (point a, point b) { return a.x*b.x + a.y*b.y; } int ConvexHull (point *p, point *ch, int n) { sort (p, p+n); int m = 0; for (int i = 0; i < n; i++) { while (m > 1 && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } int k = m; for (int i = n-2; i >= 0; i--) { while (m > k && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } if (n > 1) m--; return m; } int cnt,n; point p[maxn],ch[maxn]; bool OnSegment (point p, point a1, point a2)//点在线段上(不包含端点) { return dcmp (cross (a1-p, a2-p)) == 0 && dcmp (dot (a1-p, a2-p)) < 0; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0; i<n; i++) { cin>>p[i].x>>p[i].y; p[i].pos=i; } if(n<6) { printf("NO\n"); continue; } else { int flag=1; cnt=ConvexHull(p,ch,n); if (cnt == 1 || cnt == 2) { printf ("NO\n"); continue; } for(int i=0; i<cnt; i++) { int temp=0; for(int j=0; j<n; j++) { if(p[j].pos!=ch[i].pos&&p[j].pos!=ch[(i+1)%cnt].pos&&OnSegment(p[j],ch[i],ch[(i+1)%cnt])) { temp++; break; } } if(temp==0) { flag=0; break; } } if(flag==1) printf("YES\n"); else printf("NO\n"); } } return 0; }
相关文章推荐
- 去掉或替换字符串中的标点符号(正则表达式)
- google正在开发新系统——Fuchsia
- mysql关联查询怎么在查询软件中一下就能查询到所有的关联数据,修改的时候也方便,对比数据
- Maven使用详解
- 写了10年Javascript未必全了解的连续赋值运算
- mysql之通过日志定时备份和恢复(上)
- 写给iOS程序员的命令行使用秘籍
- Android selector背景以及透明色
- php的三种CLI常量:STDIN,STDOUT,STDERR
- iOS之数据解析异常处理 ID_VALUE
- BZOJ 3170 [Tjoi 2013]松鼠聚会
- 海思Hi3516A(3)图像sensor驱动开发
- hadoop在windows平台下的本地模式配置
- Vector源码详解
- 测试工具之charles使用
- 关于图片压缩的三两句话
- Android NFC 对sim卡读写注意事项
- 【C++】谈一谈this指针
- 跨平台原子操作
- JavaScript知识点总结(五)之Javascript中两个等于号(==)和三个等于号(===)的区别