[POJ1113]Wall(凸包)
2017-01-03 08:37
337 查看
题目描述
传送门题意:给出一个多边形,要在外围距离r围一圈围墙,求围墙的长度
题解
nπ−(n−3)π=2π所以就是求凸包周长然后加上一个圆周的长
从图里很清楚能看出来
Graham求凸包裸题
代码
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define N 1005 const double pi=acos(-1.0); const double eps=1e-9; int dcmp(double x) { if (x<=eps&&x>=-eps) return 0; return (x>0)?1:-1; } struct Vector { double x,y; Vector(double X=0,double Y=0) { x=X,y=Y; } bool operator < (const Vector a) const { return x<a.x||(x==a.x&&y<a.y); } }; typedef Vector Point; Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x,A.y-B.y);} int n,top; double r,x,y,ans; Point p ,stack ; double Dot(Vector A,Vector B) { return A.x*B.x+A.y*B.y; } double Cross(Vector A,Vector B) { return A.x*B.y-A.y*B.x; } double Len(Vector A) { return sqrt(Dot(A,A)); } void Graham() { sort(p+1,p+n+1); for (int i=1;i<=n;++i) { while (top>1&&dcmp(Cross(stack[top]-stack[top-1],p[i]-stack[top-1]))<=0) --top; stack[++top]=p[i]; } int k=top; for (int i=n-1;i>=1;--i) { while (top>k&&dcmp(Cross(stack[top]-stack[top-1],p[i]-stack[top-1]))<=0) --top; stack[++top]=p[i]; } if (n>1) --top; } int main() { freopen("input.in","r",stdin); scanf("%d%lf",&n,&r); for (int i=1;i<=n;++i) { scanf("%lf%lf",&x,&y); p[i]=Point(x,y); } Graham(); for (int i=1;i<=top;++i) ans+=Len(stack[i]-stack[i%top+1]); ans+=2.0*pi*r; printf("%.0lf\n",ans); }
相关文章推荐
- poj1113-Wall (国王的凸包)
- POJ1113 Wall【凸包】
- 【POJ1113】Wall(凸包)
- [poj1113][Wall] (水平序+graham算法 求凸包)
- 【POJ1113】Wall-Graham-Scan算法求凸包
- kyeremal-poj1113-Wall-凸包
- Wall_poj1113_凸包
- POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)
- poj1113--Wall(凸包)
- [POJ1113]Wall(计算几何-凸包)
- Wall--POJ1113(极角排序+求凸包)
- POJ1113浅析——Wall ——凸包
- 学习凸包(五):卷包裹算法--兼解POJ1113(JAVA)
- Wall(HDU1348,凸包周长)
- timus 1185. Wall URAL 解题报告 凸包
- POJ 1113 Wall(凸包应用)
- [POJ1113] Wall && 计算几何
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall(凸包)
- 【凸包构造】poj 1113 Wall