WA Subtask #0 #6 Subtask #1 #2求助
查看原帖
WA Subtask #0 #6 Subtask #1 #2求助
1313601
houbur楼主2024/9/23 21:04

不懂

#include<bits/stdc++.h>
using namespace std;
const int N=2e6+5;
int n,m,top,xx,yy;
struct sb{
	double x,y;
}e[N];
sb st[N];
inline bool cmp(sb a,sb b){return (a.y==b.y)?(a.x<b.x):(a.y<b.y);}
inline double dis(sb a,sb b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
inline double cross(sb a,sb b,sb c){return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);}
inline bool cmpp(sb a,sb b){
	double k1=atan2(a.y-yy,a.x-xx),k2=atan2(b.y-yy,b.x-xx);
	if(k1!=k2)return k1<k2;
	if(a.x==b.x)return a.y<b.y;
	return a.x<b.x;
}
signed main(){
	// freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>e[i].x>>e[i].y;
	sort(e+1,e+1+n,cmp);
	st[++top]=e[1];
	xx=st[top].x,yy=st[top].y;
	sort(e+2,e+1+n,cmpp);
	st[++top]=e[2];
	for(int i=3;i<=n;i++){
		while(top>1&&cross(st[top-1],st[top],e[i])<=0)top--;
		st[++top]=e[i];
	}
	for(int i=1;i<=top;i++)st[i+top]=st[i];
	int mx=0,l=1,r=1;
	for(int i=1;i<=top;i++){
		int op=dis(st[i],st[1]);
		if(op>mx){mx=op;r=i;}
		else break;
	}
	double ans=0;
	// cout<<top<<endl;
	for(l=1;l<=top;l++){
		while(r<=top*2&&dis(st[r+1],st[l])>dis(st[r],st[l]))r++;
		ans=max(ans,dis(st[r],st[l]));
	}printf("%.6lf",ans);
	return 0;
}
2024/9/23 21:04
加载中...