poj 1113 Wall
来源:互联网 发布:淘宝买家秀大尺度店铺 编辑:程序博客网 时间:2024/04/27 15:33
题意:国王要建一座墙围住国王所有的城堡,要求墙上任意一点到城堡的距离大于L,同时墙的长度最短。输出墙的长度(四舍五入)。
墙的长度 = 城堡的点构成的凸包的长度 + 以L为半径的圆的周长
黑色的是城堡连接成的凸包,外围黄色的部分是墙,顶点上 是圆弧
#include <iostream>#include <algorithm>#include <cmath>using namespace std;const int Max = 1005;const double PI = 3.141592653;struct Point{ double x, y;}p[Max];int n, res[Max], top;bool cmp(struct Point a, struct Point b){ if(a.y == b.y) return a.x < b.x; return a.y < b.y;}double mult(Point sp, Point ep, Point op){ return (sp.x-op.x)*(ep.y-op.y) - (ep.x-op.x)*(sp.y-op.y);}double mydis(int i, int j){ double a = p[i].x - p[j].x; double b = p[i].y - p[j].y; return sqrt(a*a + b*b);}void Graham(){ int i, len; top = 1; sort(p, p+n, cmp);//p[0]是最左下的点,p[n-1]是最右上的点 for(i = 0; i < 3; i ++) res[i] = i; for(i = 2; i < n; i ++){ while(top && mult(p[i], p[res[top]], p[res[top-1]]) >= 0) top --; res[++ top] = i; }//凸包画了下面一半 len = top; res[++ top] = n-2; for(i = n - 3; i >= 0; i --){ while(top != len && mult(p[i], p[res[top]], p[res[top-1]]) >= 0) top --; res[++ top] = i; }//剩下一半}int main(){ int i; double r, ans; scanf("%d%lf", &n, &r); for(i = 0; i < n; i ++) scanf("%lf%lf", &p[i].x, &p[i].y); Graham(); ans = 2 * PI * r; for(i = 0; i < top-1; i ++) ans += mydis(res[i], res[i+1]); ans += mydis(res[0], res[top-1]); printf("%.lf\n", ans); return 0;}
0 0
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 wall
- poj 1113 Wall
- POJ 1113 wall
- poj 1113 Wall
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113(Wall-Quickhull)
- POJ 1113 Wall
- poj-1113-Wall
- poj 1113 Wall
- POJ 1113 Wall
- POJ 1113 Wall
- poj - 1113 - Wall
- windows绑定应用程序快捷方式到鼠标右键
- MAC系统指定JDK版本的方法
- bash下面快捷键命令
- XSLT2.0 从外部读取信息并分析生成对应文件.采用xsl:for-each-group进行排序输出
- AOP( aspect-oriented programming)面向切面编程
- poj 1113 Wall
- String StringBuffer StringBuilder关系总结
- Java中Array与ArrayList的区别
- Android Lint
- 最大流
- Java并发编程:volatile关键字解析
- POJ 1042-Gone Fishing
- Caffe源码解读1 —— Blob
- tslib ts_test显示界面,但触摸无反应,运行qt4命令触摸有反应