"No regrets."

# [POJ1113]Wall（凸包）

## 题解

nπ(n3)π=2π$n\pi-(n-3)\pi=2\pi$

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[N],stack[N];

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);
}

#### POJ 1113 Wall 凸包(模板题)

2017-04-18 15:50:32

#### poj1113 Wall 凸包

2015-08-07 20:42:42

#### POJ1113Wall（计算几何基础）

2013-05-25 21:23:14

#### POJ1113：Wall（凸包）

2017-09-15 17:34:59

#### poj1113 Wall 凸包

2017-07-23 15:40:09

#### poj1113 Wall【凸包】

2017-04-18 17:11:42

#### [POJ1113]Wall（计算几何-凸包）

2018-01-18 19:32:04

#### POJ1113浅析——Wall ——凸包

2012-08-01 17:02:56

#### POJ1113 Wall（凸包周长）

2014-03-27 00:30:33

#### poj1113——Wall（凸包）

2017-02-26 16:16:55