当前位置: 代码迷 >> 综合 >> Codeforces Round #340 (Div. 2)C. Watering Flowers
  详细解决方案

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

热度:5   发布时间:2023-12-17 08:18:28.0

C. Watering Flowers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 nx1y1x2y2 (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.

Examples
input
2 -1 0 5 3
0 2
5 2
output
6
input
4 0 0 5 0
9 4
8 3
-1 0
1 4
output
33
Note

The first sample is (r12?=?5r22?=?1):The second sample is (r12?=?1r22?=?32):

题意:给出两个圆的圆心坐标给出平面的一些点,问这两个圆将所有的点覆盖的两个半径 r12?+?r22. ;的最小值。

解题思路:考虑求其最小值则必有点在两圆上因此暴力枚举即可。

/* ***********************************************
Author       : ryc
Created Time : 2016-08-10 Wednesday
File Name    : E:\acm\codeforces\340C.cpp
Language     : c++
Copyright 2016 ryc All Rights Reserved
************************************************ */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
#include<stack>
#include<map>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int maxn=2010;
struct Node{LL r1,r2;
}A[maxn];
LL Sqr(LL x){return x*x;
}
bool cmp(Node a,Node b){return a.r1<b.r1;
}
int main()
{LL n,X1,Y1,X2,Y2;scanf("%lld%lld%lld%lld%lld",&n,&X1,&Y1,&X2,&Y2);for(int i=1;i<=n;++i){LL x,y;scanf("%lld%lld",&x,&y);A[i].r1=Sqr(x-X1)+Sqr(y-Y1);A[i].r2=Sqr(x-X2)+Sqr(y-Y2);}sort(A+1,A+n+1,cmp);LL ans=1e16;A[0].r1=A[0].r2=0;for(int i=0;i<=n;++i){LL temp=0;for(int j=i+1;j<=n;++j){temp=max(temp,A[j].r2);}ans=min(ans,A[i].r1+temp);}printf("%lld\n",ans);return 0;
}


  相关解决方案