问
查看原帖
问
882043
continueOI喵呜ˆωˆ楼主2023/11/5 18:48

为什么空间开到 200010200010 就能 AC 而 101000101000 不能。

code:

#include<bits/stdc++.h>
using namespace std; 
const double eps=1e-6;
struct vec{
	double x,y;
	vec(double x=0,double y=0):x(x),y(y){} 
};
inline bool operator < (const vec &a,const vec &b){
	if(fabs(a.x-b.x)<eps) return a.y<b.y;
	return a.x<b.x;
}
int n;
vec p[200010],st[200010];
double cross(vec a,vec b){
    return a.x*b.y-a.y*b.x;
}
double side(vec a,vec b,vec p){
    vec A=vec(b.x-a.x,b.y-a.y);
    vec B=vec(p.x-a.x,p.y-a.y);
    return cross(A,B);
}
int Andrew(){
    sort(p+1,p+n+1);
    if(n<3)
    	return 0;
    int top=0;
    st[++top]=p[1],st[++top]=p[2];
    for(int i=3;i<=n;i++){
        while(top&&side(st[top-1],st[top],p[i])<0.0){
        	if(top==1) break;
        	top--;
		}
        st[++top]=p[i];
    }
    int tmp=top;
    st[++top]=p[n],st[++top]=p[n-1];
    for(int i=n-2;i>=1;i--){
        while(top&&side(st[top-1],st[top],p[i])<0.0){
        	if(top==tmp+1) break;
        	top--;
		}
        st[++top]=p[i];
    }
    return top;
}
double dis(vec p1,vec p2){
    return sqrt((p2.y-p1.y)*(p2.y-p1.y)+(p2.x-p1.x)*(p2.x-p1.x));
}
double ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>p[i].x>>p[i].y;
	int cnt=Andrew();
	for(int i=1;i<cnt;i++){
		ans+=dis(st[i],st[i+1]);
	}
	printf("%.2lf",ans);
	return 0;
}
2023/11/5 18:48
加载中...