Wa on #1,#2,#3
查看原帖
Wa on #1,#2,#3
664908
lbdontknow楼主2023/5/18 23:45

悬关

#include<bits/stdc++.h>
using namespace std;
const double Exp=1e-8;
int sgn(double x){
    if(fabs(x)<Exp) return 0;
    return x<0?-1:1;
}
class Point{
    public:
    double x;
    double y;
    Point(){}
    Point(double _x,double _y):x(_x),y(_y){}
    Point operator-(Point B){return Point(x-B.x,y-B.y);}
    bool operator<(Point B){
        if(!sgn(x))  return x<B.x;
        return y<B.y;
    }
    bool operator==(Point B){
        if(!sgn(fabs(x-B.x))&&!sgn(fabs(y-B.x)))    return true;
        return false;
    }
};
typedef Point Vector;
double Cross(Vector A,Vector B){
    return A.x*B.y-A.y*B.x;
}
int n;
int cnt;
Point stk[1919810],p[1919810];
double ans;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)   cin>>p[i].x>>p[i].y;
    sort(p,p+n);
    int limit=1;
    for(int i=0;i<n;i++){
        while(cnt>limit&&sgn(Cross(stk[cnt-1]-stk[cnt-2],p[i]-stk[cnt-2]))<=0) cnt--;
        stk[cnt++]=p[i];
    }
    limit=cnt;
    for(int i=n-2;i>=0;i--){
        while(cnt>limit&&sgn(Cross(stk[cnt-1]-stk[cnt-2],p[i]-stk[cnt-2]))<=0) cnt--;
        stk[cnt++]=p[i];
    }
    if(n>1) cnt--;
    for(int i=0;i<cnt;i++) ans+=hypot(stk[(i+1)%cnt].x-stk[i].x,stk[(i+1)%cnt].y-stk[i].y);
    printf("%0.2f\n",ans);
    return 0;
}
2023/5/18 23:45
加载中...