题目: 传送门
思路:
对于每朵花,我们先算出它关于两个喷泉的最小距离,即要 覆盖该花 的最小 R;
由于每朵花都被其中一个喷泉覆盖,我们不妨假设 喷泉 1 的半径为 R1,则 R2 = max(不能被R1覆盖的花被2覆盖所需要的R)。经分析,该算法的复杂的为o( n2 ).可以满足.
在我们枚举 R1的时候可以从小到大枚举,也可以从大到小枚举.
struct node {
long long r1,r2;
};
node s[2100];
bool cmp(const node&a,const node&b) {
if(a.r1!=b.r1)return a.r1<b.r1;
else return a.r2>b.r2;
}
long long r1d(long long x,long long y) {
return (x-x1)*(x-x1)+(y-y1)*(y-y1);
}
long long r2d(long long x,long long y) {
return (x-x2)*(x-x2)+(y-y2)*(y-y2);
}
int main() {
cin>>n>>x1>>y1>>x2>>y2;
for(int i = 1;i<=n;i++){
long long x,y;
cin>>x>>y;
s[i].r1 = r1d(x,y);
s[i].r2 = r2d(x,y);
//cout<<s[i].r1<<' '<<s[i].r2<<endl;
}
s[0].r1 =0,s[0].r2=0;
sort(s,s+n+1,cmp);
long long ans = 1e18;
for(int i=0;i<=n;i++) {
long long d = 0;
for(int j=i+1;j<=n;j++) {
d=max(s[j].r2,d);
}
// cout<<d<<' '<<s[i].r1<<endl;
ans=min(d+s[i].r1,ans);
}
cout<<ans<<endl;
return 0;
}