Codeforces Round #340 (Div. 2)C. Watering Flowers(暴力)

题意:在笛卡尔坐标系中给出n个点和两个圆心坐标,以两个点为圆心画圆,要求所画的圆能够覆盖坐标系内所有的点,求r1^2+r2^2的最小值;

思路:先计算出所有点到第一个圆心的距离,然后以此为半径,直接枚举。需要注意的是范围大于int


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

typedef long long  ll;
const ll INF=1e18;
const int maxn=2005;
int n,x1,y1,x2,y2;

struct Point{
	ll x,y;
	ll dis1;
	ll dis2;
}point[maxn];

ll getDis1(ll x,ll y){
	return (x-x1)*(x-x1)+(y-y1)*(y-y1);
}

ll getDis2(ll x,ll y){
	return (x-x2)*(x-x2)+(y-y2)*(y-y2);
}

int main(){
	while(~scanf("%d%d%d%d%d",&n,&x1,&y1,&x2,&y2)){
		for(int i=1;i<=n;i++){
			scanf("%I64d%I64d",&point[i].x,&point[i].y);
			point[i].dis1=getDis1(point[i].x,point[i].y);
			point[i].dis2=getDis2(point[i].x,point[i].y);
		}
		point[0].dis1=point[0].dis2=0;
		ll ans=INF;
		ll r1=0,r2=0;
		for(int i=0;i<=n;i++){
			r1=point[i].dis1;
			r2=0;
			for(int j=1;j<=n;j++){
				if(point[j].dis1<=r1) continue;
				if(point[j].dis2>r2)
					r2=point[j].dis2;
			}
			ans=min(ans,r1+r2);
		}
		if(n==1) ans=min(point[1].dis1,point[1].dis2);
		printf("%I64d\n",ans);
	}
	return 0;
}


你可能感兴趣的:(Codeforces Round #340 (Div. 2)C. Watering Flowers(暴力))