HDU 5533 Dancing Stars on Me(凸包)
2015-11-04 16:30
369 查看
题目大意
给出n个点,判断这n个点能否构成一个等边的严格凸包分析
首先直接求凸包,判断是不是n个点全部用到了。再依次比较每条边是否相等。
代码
#include <iostream> #include <cmath> #include <algorithm> using namespace std; const int maxn = 110; struct point { int x , y; bool operator < (point const &rhs) const { return (x < rhs.x || (x == rhs.x && y < rhs.y)); } }; point p[maxn] , ch[maxn]; int cross(point const &O , point const &A , point const &B){ int xoa = A.x - O.x; int yoa = A.y - O.y; int xob = B.x - O.x; int yob = B.y - O.y; return xoa * yob - yoa * xob; } double dis(point A , point B) { return sqrt((double)(A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)); } int ConvexHull(point *p , int n , point *ch) { sort(p , p + n); int m = 0; for(int i = 0; i < n; i++) { while(m > 1 && cross(p[i] , ch[m-1] , ch[m-2]) < 0) m--; ch[m++] = p[i]; } int k = m; for(int i = n - 2; i >= 0; i--) { while(m > k && cross(p[i] , ch[m-1] , ch[m-2]) < 0) m--; ch[m++] = p[i]; } if(n > 1) m--; return m; } int main() { int t , n; cin >> t; while(t--) { cin >> n; for(int i = 0; i < n; i++) cin >> p[i].x >> p[i].y; int cnt = ConvexHull(p , n , ch); if(cnt != n) cout << "NO" << endl; else { double d = dis(ch[0] , ch[1]); int sign = 1; for(int i = 2; i < n; i++) { double tmp = dis(ch[i-1] , ch[i]); if(tmp != d) {sign = 0; break;} } double tmp = dis(ch[0] , ch[n-1]); if(tmp != d) sign = 0; if(sign) cout << "YES" << endl; else cout << "NO" << endl; } } return 0; }
相关文章推荐
- Matlab坐标修改 gca
- Android M 新的运行时权限开发者需要知道的一切
- 据文字动态确定Label宽高
- 统计模式识别的原理与方法
- spark安装入门
- 涨姿势!关于可访问性设计师必知的7件事情(下)
- Python中如何实现两个字典合并
- 四则运算java实现
- 为什么说串行比并行快?
- Apache Commons工具集简介(转)
- UIImageView和UIButton区别
- Java微观探源(一)_开篇
- ListSet_对半搜索的递归算法
- 涨姿势! 对于可访问性设计师必知的7件事(上)
- Dell服务器安装卸载监控Open Manage
- CentOS源码安装GitLab汉化版
- Task线程 同时执行多个任务
- Ubuntu 14.04 64bit上编译安装simple-rtmp-server(srs)服务器
- HDU5512 Pagodas(博弈)
- [OpenJudge-NOI]算24 Dfs