Wall POJ - 1113 

题意 : 求凸包周长

思路:处理出凸包,两点距离公式

#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=3e5+5;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
int sign(double x){
    return abs(x)<1e-7?0:x<0?-1:1;
}
struct Point{
    double x,y;
    Point(double x=0.0, double y=0.0) : x(x), y(y) {}
    Point operator - (const Point &rhs) const{
        return Point(x-rhs.x,y-rhs.y);
    }
    bool operator == (const Point &rhs) const{
        return sign(x-rhs.x)==0&&sign(y-rhs.y)==0;
    }
    bool operator < (const Point &rhs)const{
        if(x==rhs.x)    return y<rhs.y;
        else    return x<rhs.x;
    }
};
typedef Point Vector;
double cross(Vector A,Vector B){
    return A.x*B.y-A.y*B.x;
}
int n;
typedef vector<Point> Polygon;
Polygon convex_hull(Polygon P){
    sort(P.begin(),P.end());
    P.erase(unique(P.begin(), P.end()), P.end());
    int n=P.size(),k=0;
    Polygon Q(n*2);
    for(int i=0;i<n;++i){
        while(k>1&&cross(Q[k-2]-Q[k-1],Q[k-2]-P[i])<=0) k--;
            Q[k++]=P[i];
    }
    int t=k;
    for(int i=n-2;i>=0;--i){
        while(k>t && cross(Q[k-2]-Q[k-1],Q[k-2]-P[i])<=0)   k--;
        Q[k++]=P[i];
    }
    Q.resize(k);
    return Q;
}
double dis(Point a,Point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main(void){
    int r;
    while(cin>>n>>r){
        Polygon t;
        for(int i=1;i<=n;i++){
            double x,y;
            scanf("%lf%lf",&x,&y);
            t.push_back({x,y});
        }
        vector<Point> ans=convex_hull(t);
        double res=0.0;
//        cout <<"---------"<<endl;
//        for(auto  t : ans)  cout << t.x <<" "<<t.y<<endl;
//        ans.pb(ans[0]);
        for(int i=0;i<(int)ans.size()-1;++i)    res+=dis(ans[i],ans[i+1]);
//        printf("area=%f\n",res);
        if(res<0)   res=-res;
        res+= 2.0*PI*r;
//        printf("area=%f\n",res);
        printf("%d\n",(int)(res+0.5));
    }
    return 0;
}