bsoj:1773 -- 【模拟试题】最远距离点对

1773 -- 【模拟试题】最远距离点对

Description

  给定平面上的n个点,找出它们之间最远的点对。

Input

  多组数据,每组第一行n代表点数,接着n行为点的坐标,坐标为整数,不超过Longint范围。n<=30000。

Output

  每组一行,最远点对的距离,保留2位小数

Sample Input

  4  0 0  1 1  0 1  1 0

Sample Output

  1.41




第一次旋转卡壳呢:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct Vector{
 	double x,y;
    Vector operator +(Vector &a){
    	Vector v1;
    	v1.x=this->x+a.x,v1.y=this->y+a.y;
    	return v1;
		};
    Vector operator -(Vector &a){
   	 	Vector v1;
    	v1.x=this->x- a.x,v1.y=this->y -a.y;
	    return v1;
		};
    double operator * (Vector &a){
	    return ((this->x)*a.y)-(a.x*(this->y));
		};
}P[500055] ; 
int n;
int ch[500005];
bool  vis[500005];
int top=0;
bool cmp(Vector a,Vector b){
	return (a.y<b.y)||((a.y==b.y)&&(a.x<b.x));
}
bool Judge(Vector a,Vector b,Vector c){
	Vector q=b-c;
	Vector w=a-c;
	return q*w>=0;
}
double Get_Area(Vector a,Vector b,Vector c){
	a=a-c;
	b=b-c;
	return a*b;
}
double Get_Long(Vector a,Vector b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void TUBao(){
	sort(P+1,P+1+n,cmp);
	ch[++top]=1;
	int k=2;
	while(k<=n){
		while(top>1&&Judge(P[ch[top]],P[k],P[ch[top-1]]))
		vis[ch[top--]]=0;
		ch[++top]=k;
		vis[k]=1;	
		k++;	
	}
	int Max=top;
	k=n-1;
	while(k>=1){
		while(vis[k])k--;
		while(top>Max&&Judge(P[ch[top]],P[k],P[ch[top-1]]))
		vis[ch[top--]]=0;
		ch[++top]=k;
		vis[k]=1;
		k--; 
	}
}
void Rotating_calipers(){
	int p=2;
	double ans=0.0;
	for(int q=1;q<top;q++){
		while(Get_Area(P[ch[q]],P[ch[q+1]],P[ch[p+1]])>Get_Area(P[ch[q]],P[ch[q+1]],P[ch[p]]))p=(p+1)%(n+1);
		ans=max(ans,max(Get_Long(P[ch[q]],P[ch[p]]),Get_Long(P[ch[q+1]],P[ch[p+1]])));
	}
	printf("%.2lf",ans);
}
int main(){

	while(scanf("%d",&n)==1){
	for(int i=1;i<=n;i++){
		scanf("%lf%lf",&P[i].x,&P[i].y);
	}
	TUBao();
	Rotating_calipers();
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值