HDU 5533 Dancing Stars on Me(凸包)
来源:互联网 发布:sql数据库完全备份 编辑:程序博客网 时间:2024/05/20 01:38
题目大意
- 给出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;}
0 0
- HDU 5533 Dancing Stars on Me(凸包)
- HDU 5533 Dancing Stars on Me (凸包)
- hdu 5533 Dancing Stars on Me
- hdu 5533 Dancing Stars on Me
- HDU 5533 Dancing Stars on Me
- hdu 5533 Dancing Stars on Me
- HDU 5533:Dancing Stars on Me【数学】
- HDU 5533 Dancing Stars on Me
- HDU 5533 Dancing Stars on Me [数学]
- HDU 5533 Dancing Stars on Me
- HDU-5533 Dancing stars on me
- HDOJ 5533 Dancing Stars on Me(凸包,convex hall)
- hdu 5533 Dancing Stars on Me(水)
- HDU 5533 Dancing Stars on Me(数学+水题)
- HDU 5533 Dancing Stars on Me (暴力模拟+思维)
- HDU Dancing Stars on Me
- Dancing Stars on Me HDU
- HDU杭电5533 Dancing Stars on Me
- stream, parser, 文法的一些概念
- 四则运算java实现
- 据文字动态确定Label宽高
- Matlab坐标修改 gca
- monkeyrunner自动化测试工具--真机运行提示:could not connect to view server
- HDU 5533 Dancing Stars on Me(凸包)
- Servlet中的过滤器Filter详解
- 统计模式识别的原理与方法
- ListSet_对半搜索的迭代算法
- Eclipse \tmp0\work\Catalina\localhost\_\SESSIONS.ser (系统找不到指定的路径。)
- 涨姿势!关于可访问性设计师必知的7件事情(下)
- <iOS>iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用
- 模板_树状数组(BIT)
- 冬天里的外套