[HDU 1348] Wall 凸包周长
来源:互联网 发布:js currenttimemillis 编辑:程序博客网 时间:2024/04/30 03:55
http://acm.hdu.edu.cn/showproblem.php?pid=1348
题意:一个国王要求建筑师修一堵墙,围绕他的城堡,且墙与城堡之间的距离总不小于L输入节点和L求周长
思路:先求出凸包,然后求出周长加上一个半径为 L 的圆的周长,因为多边形只有再顶点处外面的墙才会形成圆弧,其他地方的墙和凸包的边平行。由于任意多边形外角和都是 360° 所以外面墙的周长就是凸包周长加上以 L 为半径的圆的周长。
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1010;struct Point{ int x, y; friend bool operator < (Point a, Point b){ return a.y < b.y || (a.y == b.y && a.x < b.x); }};Point res[maxn];Point point[maxn];double mult(Point a, Point b, Point c){ return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);}int graham(int n, Point *point, Point *res){ sort(point, point+n); if(n == 0) return 0; res[0] = point[0]; if(n == 1) return 1; res[1] = point[1]; if(n == 2) return 2; res[2] = point[2]; int top = 1; for(int i = 2; i < n; i++){ while(top && mult(point[i], res[top], res[top-1]) >= 0){ top--; } res[++top] = point[i]; } int len = top; for(int i = n-2; i >= 0; i--){ while(top > len && mult(point[i], res[top], res[top-1]) >= 0){ top--; } res[++top] = point[i]; } return top;}double length(Point a, Point b){ return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}int main(){ int Test; cin>>Test; while(Test--){ int n, l; cin>>n>>l; for(int i = 0; i < n; i++){ cin>>point[i].x>>point[i].y; } int top = graham(n, point, res); double ans = 0; for(int i = 1; i <= top; i++){ ans += length(res[i], res[i-1]); } ans += length(res[top], res[0]) + 2.0 * l * 3.1415926535897932384626; cout<<int(ans+0.5)<<endl; if(Test) cout<<endl; } return 0;}
0 0
- HDU 1348 Wall 凸包的周长
- [HDU 1348] Wall 凸包周长
- [ACM] hdu Wall (凸包周长)
- nyoj 226 && hdu HDU 1348 && poj 1113 wall [凸包周长]
- POJ 1113 && HDU 1348 Wall (凸包周长 graham扫描法)
- HDU-1348 Wall 凸包
- Hdu 1348 Wall 凸包
- hdu-1348 Wall(凸包)
- poj 1113 Wall(凸包周长)
- POJ 1113 Wall【凸包周长】
- Wall(HDU1348,凸包周长)
- POJ 1113 Wall (凸包周长)
- POJ1113 Wall(凸包周长)
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall(凸包 多边形周长)
- POJ 1113 Wall(凸包周长)
- POJ--1113[Wall] 凸包周长+圆的周长
- hdu 1348(凸包的周长+圆的周长)
- Java之集合类【ArrayList】【入门版,实例解析】
- springAOP模板
- MD5工具类 -- 文件MD5值 -- MD5加密
- 读书笔记-《用户体验设计》
- 冒泡排序--改进
- [HDU 1348] Wall 凸包周长
- VC6\VS2003 转换到VS2005 时可能会遇到的问题以及解决方法
- 第十二天 网络连接
- 读书笔记--TCP连接建立与终止
- QT中文乱码的问题
- Codeforces 557 D. Vitaly and Cycle
- python中input输出“Name 'XXX' is not defined问题
- Java之集合类【HashSet】【入门版,实例解析】
- 【练习笔记】剑指offer-数的整次方