【?】编译器输出0.00,但能过
查看原帖
【?】编译器输出0.00,但能过
581811
yilot楼主2022/6/7 19:03
#include<bits/stdc++.h>
using namespace std;
int tot,n;
double ans;
struct node{
	double x,y;
}a[100005],q[100005];
double cj(node x1,node x2,node x3,node x4)
{
	return (x2.x-x1.x)*(x4.y-x3.y)-(x2.y-x1.y)*(x4.x-x3.x);
}
double dis(node x,node y)
{
	return 1.0*sqrt(1.0*(x.x-y.x)*(x.x-y.x)+1.0*(x.y-y.y)*(x.y-y.y));
}
bool cmp(node x,node y)
{
	double s=cj(a[1],x,a[1],y);
	if(s>0)return 1;
	if(s<0)return 0;
	if(s==0&&dis(a[1],x)<dis(a[1],y))return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lf%lf",&a[i].x,&a[i].y);
		if(a[i].y<a[1].y||(a[i].y==a[1].y&&a[i].x<a[1].x))
			swap(a[i],a[1]);
	}
	sort(a+2,a+n+1,cmp);
	q[++tot]=a[1];
	for(int i=2;i<=n;i++)
	{
		while(tot>1&&cj(q[tot-1],q[tot],q[tot],a[i])<=0)tot--;
		q[++tot]=a[i];
	}
	q[tot+1]=a[1];
	for(int i=1;i<=tot;i++)	ans+=dis(q[i],q[i+1]);
	printf("%.2lf",ans);
	return 0;
}
2022/6/7 19:03
加载中...