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

C. Watering Flowers

题目连接:

http://www.codeforces.com/contest/617/problem/C

Descriptionww.co

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.

Input

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.

Output

Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.

Sample Input

2 -1 0 5 3

0 2

5 2

Sample Output

6

Hint

题意

有一个花园,有两个喷水龙头,你需要浇灌花园里面所有的花

两个喷水龙头的喷水半径分别是r1,r2

你需要使得r1*r1+r2*r2最小

请问是多少

题解:

将其中一维排序,然后另外一维直接取剩下的最大值就好了

代码

#include<bits/stdc++.h>
using namespace std;
struct node
{
long long x,y;
}; node p[2];
node point[2005];
long long pre[2005];
bool cmp(node a,node b)
{
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
int main()
{
int n;scanf("%d",&n);
for(int i=0;i<2;i++)
scanf("%lld%lld",&p[i].x,&p[i].y);
for(int i=1;i<=n;i++)
{
long long x,y;
scanf("%lld%lld",&x,&y);
point[i].x = (x-p[0].x)*(x-p[0].x)+(y-p[0].y)*(y-p[0].y);
point[i].y = (y-p[1].y)*(y-p[1].y)+(x-p[1].x)*(x-p[1].x);
}
sort(point+1,point+1+n,cmp);
for(int i=n;i>=1;i--)
pre[i]=max(pre[i+1],point[i].y);
long long ans = pre[1];
for(int i=1;i<=n;i++)
ans = min(ans,point[i].x+pre[i+1]);
cout<<ans<<endl;
}
上一篇:maven到Gradle,一些对比和分享


下一篇:Zxing 的集成 ---- Maven 对应 Gradle 的写法