Description

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 nx1, y1, x2, y2 (1 ≤ n ≤ 2000,  - 10^7 ≤ x1, y1, x2, y2 ≤ 10^7) — 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 ( - 10^7 ≤ xi, yi ≤ 10^7) — 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 r1^2 + r2^2. 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 (r1^2 = 5, r2^2 = 1):

The second sample is (r1^2 = 1, r22 = 3^2):

首先,我们保存每一个花坛与两个喷泉的距离(平方),记为r1 r2

我们以其中r1的第一个距离作为开始。开始往后面遍历,如果发现后面有距离超过起始点,说明有没有覆盖的

那么把超过点的放在r2的覆盖的范围内,加起来。遍历完毕取最小值

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x7fffffff
#define INFL 0x7fffffffffffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
pair<LL,LL> q[2002];
int main()
{
LL n,x1,y1,x2,y2;
LL x,y;
cin>>n>>x1>>y1>>x2>>y2;
for(int i=0;i<n;i++)
{
cin>>x>>y;
q[i+1].first=(x-x1)*(x-x1)+(y-y1)*(y-y1);
q[i+1].second=(x-x2)*(x-x2)+(y-y2)*(y-y2);
// cout<<q[i+1].first<<" "<<q[i+1].second<<endl;
}
LL sum=INFL;
for(int i=0;i<=n;i++)
{
LL ans_1,ans_2=0;
ans_1=q[i].first;
// cout<<q[i].first<<"A"<<endl;
for(int j=1;j<=n;j++)
{
if(q[j].first>ans_1)
{
ans_2=max(ans_2,q[j].second);
}
}
// cout<<ans_2<<"B"<<endl;
// cout<<ans_1+ans_2<<"C"<<endl;
sum=min(sum,ans_1+ans_2);
// cout<<sum<<"C"<<endl;
}
cout<<sum<<endl;
return 0;
}

  

Codeforces Round #340 (Div. 2) C的更多相关文章

  1. [Codeforces Round #340 (Div. 2)]

    [Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...

  2. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法

    E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...

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

    C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...

  4. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  5. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  6. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  7. 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)

    题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...

  8. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 【莫队算法 + 异或和前缀和的巧妙】

    任意门:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 ...

  9. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number —— 莫队算法

    题目链接:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 ...

  10. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number (莫队)

    题目链接:http://codeforces.com/contest/617/problem/E 题目大意:有n个数和m次查询,每次查询区间[l, r]问满足ai ^ ai+1 ^ ... ^ aj ...

随机推荐

  1. 数据从HDFS-->HIVE-->HBASE 执行过程

    1.数据已经load进去hdfs 2.hive.hbase已经安装成功(我用的是hadoop 2.4 hbase 0.98.12 hive 1.2.1) 3.开始! 4.在hive建立表同时生成对应的 ...

  2. cookie禁用后非重定向跳转时session的跟踪

  3. 基于C++求两个数的最大公约数最小公倍数

    求x,y最大公约数的函数如下: int gys(int x,int y) { int temp; while(x) {temp=x; x=y%x; y=temp;} return y; } x=y的时 ...

  4. java中的面向对象的三大基本特征

    转载,原文来自http://blog.sina.com.cn/s/blog_5f79a56a0100c6ig.html 众所周知,java中的面向对象的三大基本特征是:[封装].[继承].[多态] 一 ...

  5. 使用绘图API自定义组件

    -----------------siwuxie095                                 工程名:CustomizeSwing 包名:com.siwuxie095.swi ...

  6. SQL serve 数据库--视图、事物、分离附加、备份还原

    视图是数据库中的一种虚拟表,与真实的表一样,视图包含一系列带有名称的行和列数据.行和列数据用来自定义视图的查询所引用的表,并且在引用视图时动态生成.  视图只能用来查询,不能增删改:不允许出现重复列 ...

  7. Linux 编译安装内核

    一.简介 内核,是一个操作系统的核心.它负责管理系统的进程.内存.设备驱动程序.文件和网络系统,决定着系统的性能和稳定性.Linux作为一个自由软件,在广大爱好者的支持下,内核版本不断更新.新的内核修 ...

  8. tomcat8.0的下载安装配置

    配置tomcat前要先配置JDK的环境变量 具体方法请点链接JDK环境变量配置 首先要 到官网下载tomcat tomcat官网 进入官网后 如图在左侧选择自己想要下载的版本,这里我以8.0版本为例 ...

  9. 面试经常问的一个问题:final、finalize、finally

    http://m.blog.csdn.net/u010980446/article/details/51493658

  10. Socket编程--TCP服务端注意事项

    僵尸进程处理 僵尸进程和孤儿进程: 基本概念:我们知道在unix/linux中,正常情况下,子进程是通过父进程创建的,子进程在创建新的进程.子进程的结束和父进程的运行是一个异步过程,即父进程永远无法预 ...