Wall(凸包)
2013-10-25 21:06
99 查看
http://poj.org/problem?id=1113
题意:给出一些点的坐标,和一个半径r,求出这些点围成的凸包的周长再加上一个半径为r的圆的周长。
View Code
题意:给出一些点的坐标,和一个半径r,求出这些点围成的凸包的周长再加上一个半径为r的圆的周长。
#include <stdio.h> #include <algorithm> #include <math.h> const double PI=acos(-1.0); const int N=1002; using namespace std; struct Point { double x; double y; Point (double x = 0,double y = 0):x(x),y(y) {} bool friend operator < (const Point &a, const Point &b) { return a.x < b.x||(a.x==b.x&&a.y < b.y); } } p ,c ; typedef Point Vector; double dis(Point A,Point B)//两点间的距离 { return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)); } Vector operator- (Point A,Point B)//求向量 { return Vector(B.x-A.x,B.y-A.y); } double Cross(Vector A,Vector B)//求叉积 { return A.x*B.y-A.y*B.x; } int ConvexHull(Point *p,int n,Point *c)//计算凸包 { int k = 0; for (int i = 0; i < n; i++) { while(k > 1 && Cross(c[k-2]-c[k-1],c[k-2]-p[i])<=0) k--; c[k++] = p[i]; } int m = k; for (int i = n-2; i >= 0; i--) { while(k > m && Cross(c[k-2]-c[k-1],c[k-2]-p[i])<=0) k--; c[k++] = p[i]; } c[k] = c[0]; return k; } int main() { int n; double r; scanf("%d %lf",&n,&r); for (int i = 0; i < n; i++) scanf("%lf %lf",&p[i].x,&p[i].y); sort(p,p+n); int cnt = ConvexHull(p,n,c); double len = 0; for (int i = 1; i <= cnt; i++) { len+=dis(c[i],c[i-1]); } len+=2*PI*r; printf("%.0f",len); return 0; }
View Code
相关文章推荐
- hdu1348 Wall(凸包模板题)
- poj 1113 Wall(Graham扫描法求凸包)
- poj 1113 Wall (凸包:周长)
- poj 1113 Wall 凸包
- POJ 1113 Wall 凸包求周长
- HDU-1348 Wall 凸包
- 【POJ】1113 Wall(凸包)
- 【计算几何】【求凸包】【POJ 1113】wall
- poj 1113 Wall (凸包模板题)
- POJ 1113 Wall (凸包求周长)
- [POJ1113]Wall(计算几何-凸包)
- poj 1113 Wall--凸包
- 【解题报告】 POJ 1113 Wall -- 求凸包周长
- poj 1113 Wall 凸包
- POJ 1113 Wall(凸包 多边形周长)
- 【计算几何初步-凸包-Graham扫描法-极角序】【HDU1348】 WALL
- poj 1113 Wall(裸凸包)
- uva 1303 - Wall(凸包)
- Poj.1113 Wall【凸包】 2015/08/29
- POJ - 1113 Wall(计算几何凸包)