A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.
You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.
The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.
Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower.
It is guaranteed that all n + 2 points in the input are distinct.
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
2 -1 0 5 3 0 2 5 2
6
4 0 0 5 0 9 4 8 3 -1 0 1 4
33
The first sample is (r12 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32):
题意: 有两个喷泉给花浇水,问这两个喷泉的半径平方和的最小值。
输入:n, x1, y1, x2, y2分别表示花的数量和两个喷泉的坐标,接下来有n 行,分别输入花的坐标
输出:输出喷泉把所有花覆盖的半径平方和的最小值。
解法:枚举所有可能出现的情况,求出最小值。
体会:对于所给常数很小的情况下,可以先采用暴力的情况,然后才是贪心。
//#define zhouV
#include<string.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long int
#define maxn 1010000
__int64 s[maxn],s1[maxn];
int main()
{
#ifdef zhouV
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
__int64 n,r1,r2,x1,x2,y1,y2,x,y,a,b,ans;
cin>>n;
r1=r2=0;
scanf("%I64d%I64d",&x1,&y1);
scanf("%I64d%I64d",&x2,&y2);
for(int i=0;i<n;i++)
{
scanf("%I64d%I64d",&x,&y);
s[i]=(x-x1)*(x-x1)+(y-y1)*(y-y1);
s1[i]=(x-x2)*(x-x2)+(y-y2)*(y-y2);
}
ans=1e18;
for(int i=0;i<n;i++)
{
r1=s[i];
r2=0;
for(int j=0;j<n;j++)
{
if(s[j]>s[i]) r2=max(r2,s1[j]);
}
ans=min(ans,r1+r2);
}
r2=0;
for(int i=0;i<n;i++)
{
r2=max(r2,s1[i]);
}
ans=min(ans,r2);
printf("%I64d\n",ans);
}