C. Watering Flowers 构造

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.

Sample test(s)
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):


题意:就是用两个已知圆心的圆将所有的点覆盖,求两个圆半径r1^2+r2^2的最小值

首先是求出其中一个圆心到其他点的距离即半径d1[i],先排序,然后再按其半径从小到大枚举,d2[j]为  0~i的相对应的点(d1[i].id)到另一个圆心的最大距离,d要求d[j]最大距离,记录最小值。




#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         using namespace std; typedef long long ll; const int N=20005; int x[N],y[N]; struct node{ ll v1,v2; bool operator <(const node&p) const{ return v1>p.v1; } } d[N]; int main() { int n; int x1,y1,x2,y2; cin>>n>>x1>>y1>>x2>>y2; int i,j; ll ans=999999999999999999,mx=0; for(i=0;i 
        
          >x[i]>>y[i]; d[i].v1=1ll*(x[i]-x1)*(x[i]-x1)+1ll*(y[i]-y1)*(y[i]-y1); d[i].v2=1ll*(x[i]-x2)*(x[i]-x2)+1ll*(y[i]-y2)*(y[i]-y2); mx=max(mx,d[i].v2); } sort(d,d+n); ans=min(d[0].v1,mx); ll s=0,s1=0,s2=0; for(i=n-1;i>=0;i--){ s1=d[i].v1; s2=0; for(j=0;j 
          
         
       
      
      
     
     
    
    
   
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值