92pts WA #1 求助
查看原帖
92pts WA #1 求助
807774
_Wind_Leaves_ShaDow_楼主2024/8/26 22:43

rt,真的调不出来了。

#include <bits/stdc++.h>
#define int long long
#define Rg register
#define Ri Rg int
#define Il inline
#define vec vector
#define pb push_back
#define fi first
#define se second
#define IT ::iterator

using namespace std;

typedef double db;
//typedef long long ll;
typedef pair<int,int> pii;
const int N=5e4,Inf=1e9;
const db eps=1e-9,pi=acos(-1.0);

int n,ans=0;
int tp=0,dtp,s[(N<<1)+5];
struct Vec{
	db x,y;
	Il Vec operator -(const Vec &a){return {x-a.x,y-a.y};}
}p[N+5];

Il bool cmp(Vec a,Vec b){return (a.x==b.x?a.y<b.y:a.x<b.x);}

Il db Cro(Vec a,Vec b){return a.x*b.y-a.y*b.x;}

Il db dir(Vec a,Vec b,Vec c){return Cro(b-a,c-a);}

Il db dis(Vec a,Vec b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}

signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;for(Ri i=1;i<=n;i++)cin>>p[i].x>>p[i].y;
	sort(p+1,p+n+1,cmp);
	for(Ri i=1;i<=n;s[++tp]=i++)while(tp>1&&dir(p[s[tp-1]],p[s[tp]],p[i])<-eps)tp--;
	if(s[tp]!=n)puts("NO!");
	dtp=tp;for(Ri i=n-1;i;s[++tp]=i--)while(tp>dtp&&dir(p[s[tp-1]],p[s[tp]],p[i])<-eps)tp--;
	for(Ri i=1,pt=1;i<tp;i++){
		while(dis(p[s[i]],p[s[pt%tp+1]])>dis(p[s[i]],p[s[pt]]))pt=pt%tp+1;
		ans=max(ans,(int)dis(p[s[i]],p[s[pt]]));
	}
	cout<<ans;
	return 0;
}
2024/8/26 22:43
加载中...