C.Watering Flowers--- (贪心+暴力) Codeforces Round #340 (Div. 2)

Watering Flowers

题目链接http://codeforces.com/contest/617/problem/C

time limit per test 2 seconds
memory limit per test 256 megabytes
C.Watering Flowers--- (贪心+暴力) Codeforces Round #340 (Div. 2)
C.Watering Flowers--- (贪心+暴力) Codeforces Round #340 (Div. 2)
C.Watering Flowers--- (贪心+暴力) Codeforces Round #340 (Div. 2)


题目大意:给你两个喷泉的坐标,再给你n个点,然后让你求两个喷泉的半径使得他们能够覆盖所有点,求r12+r22的最小值;
emmm,思路不歪的话就没什么难度,但本蒟蒻想到了三分。。。。过了4组数据WA了。。。痛定思痛之下改了贪心,A了。。。
我们可以用一个结构体保存每个点分别到A和B的距离,然后从大到小排序(按照r1)。然后我们枚举r1的最大值,那么r2的值就为:r2=max(r2,dis[i-1].r2);接下来只需取最小的ans值就好了。
当然还有一个需要注意的点就是枚举r1的时候要枚举到n+1,(即此时只有r2)。

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#define ll long long
const int mac=2000+10;
using namespace std;
struct node 
{
	double r1,r2;
	bool friend operator <(node a,node b){
	    return a.r1>b.r1;	
	}
}dis[mac];
ll pw(ll x){
	return x*x;
}
int main()
{
	ll n,x1,y1_,x2,y2,x,y;
	cin>>n>>x1>>y1_>>x2>>y2;
	for (int i=1; i<=n; i++){
		scanf ("%lld%lld",&x,&y);
		dis[i].r1=sqrt(1.0*pw(x-x1)+1.0*pw(y-y1_));
		dis[i].r2=sqrt(1.0*pw(x-x2)+1.0*pw(y-y2));
	}
	sort(dis+1,dis+1+n);
	double r1,r2=0,ans=1e17;
	for (int i=1; i<=n+1; i++){
		r1=dis[i].r1;
		r2=max(r2,dis[i-1].r2);
		ans=min(ans,r1*r1+r2*r2);
	}
	printf ("%.0f\n",ans);
	return 0;
}