HDU1392
来源:互联网 发布:淘宝上办签证被骗了 编辑:程序博客网 时间:2024/06/05 20:28
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392
凸包模板题,但是特别注意只有两个点的情况,MD两个点只能输出两点间的距离,可是题目上明明说的是surround围绕啊,MDZZ。
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const double eps = 1e-10;struct Point{ double x, y; Point() {} Point(double x_, double y_): x(x_), y(y_) {} bool operator < (const Point& a) const { if (x == a.x) return y < a.y; return x < a.x; } bool operator == (const Point& a) const { if (x == a.x && y == a.y) return true; return false; }};typedef Point Vector;Point P[110], convex[110];Vector operator - (Point A, Point B){ return Vector(A.x-B.x, A.y-B.y);}double Length(Point A, Point B){ return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));}double Cross(Vector A, Vector B) //A × B{ return A.x*B.y - A.y*B.x;}int ConvexHull(Point *p, int n, Point *ch){ int m = 0; sort(p, p+n); n = unique(p, p+n) - p; for (int i=0; i<n; i++) { while (m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 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-2]) <= 0) m--; ch[m++] = p[i]; } return m;}int main(){ int n; while (scanf("%d",&n)) { if (!n) break; for (int i=0; i<n; i++) scanf("%lf%lf",&P[i].x, &P[i].y); if (n == 1) { printf("%.2lf\n",0); continue; } else if (n == 2) { printf("%.2lf\n",Length(P[0],P[1])); continue; } int cnt = ConvexHull(P, n, convex); double ans = 0; for (int i=1; i<cnt; i++) ans += Length(convex[i-1],convex[i]); printf("%.2lf\n",ans); } return 0;}
0 0
- HDU1392
- HDU1392
- hdu1392凸包求周长
- hdu1392 凸包
- HDU1392+凸包
- 凸包:HDU1392(ZJU1453)
- hdu1392-Surround the Trees
- hdu1392标准求凸包模板
- hdu1392(一道凸包水题)
- hdu1392(凸包求周长)
- 凸包 hdu1392
- acm几何凸包hdu1392
- hdu1392-Surround the Trees 求凸包
- hdu1392凸包.叉乘
- hdu1392——Surround the Trees
- hdu1392凸包求周长 graham 3种写法
- HDU1392--Surround the Trees--凸包
- 凸包问题 hdu1392 Surround the Trees
- 热门UI框架
- 计算技术界的重大突破:1nm晶体管诞生
- 2016 年最受欢迎的编程语言是什么?
- Android增量升级方案
- 关于字符串以及数组的操作
- HDU1392
- html 03 浮动布局以及清除浮动
- 【译】4个你需要知道的Asset Catalog的秘密
- 05node.js事件驱动程序
- How Many Tables(HDU1213)(入门)
- ContentProvider中常用的常量及字段
- POJ 3600 Subimage Recognition 搜索
- Hadoop安装(一)
- PHP 远程文件包含的介绍和代码防御