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;
}

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

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

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

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

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

  3. 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 ...

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

  8. Codeforces Round #340 (Div. 2) C

    Description A flowerbed has many flowers and two fountains. You can adjust the water pressure and se ...

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

随机推荐

  1. 模式自由(Schema-free)和数据存储的非格式化趋势

    最近遐想,数据存储的非格式化趋势. 格式化表格到自由的XML存储 数年以前,多家数据库厂商开始XML数据库存储.XML数据作为一种自描述的半结构化数据为Web的数据管理提供了新的数据模型,如果将XML ...

  2. JS方式调用本地的可执行文件

    看到一个方法,有些用,先存下来,有用的时候再用. 前几天,在IE,FIREFOX中实现了用JS方式调用本地的可执行文件.地址:www.yihaomen.com/article/js/211.htm , ...

  3. python程序中自启动appium服务

    普通启动Appium服务方法:      打开cmd,运行命令: #>appium -a 127.0.0.1 -p 4723 当程序输出如上图信息的时候,表示appium启动成功,此时便可以运行 ...

  4. InputFormat 总结

    在mr中的输入类,常见的InputFormat是TextInputFormat,也是mr默认的文件处理类,处理普通文本文件,作用是 1 每一行作为一个记录,将每一行在文件中的起始偏移量做为key,内容 ...

  5. PHP相关图书推荐

    PHP和MySQL Web开发(原书第4版) 作      者 [澳] Luke Welling,[澳] Luke Welling 著:武欣 等 译 出 版 社 机械工业出版社 出版时间 2009-0 ...

  6. Windows8.1 安装office2013并激活

    之前笔记本上安装的东西太多了,启动比较慢,打算重做系统,正好同事有一个Windows8.1的系统盘,直接做了一个Windows8.1的系统.界面清爽,速度还可以,系统安装完成以后,准备安装office ...

  7. Axure rp 基础知识 转

    首先做个声明:此次教程里为了快速完成,借用了一些网上已有教程的图文,不是剽窃,只图方便.另外,因为汉化版本可能功能名称等略有差别,请自行理解. 名词解释: 线框图:一般就是指产品原型,比如:把线框图尽 ...

  8. bundle install rake-10.4.2

    这个是由于被墙了的原因,提供一个不用FQ解决的方法 淘宝做了一个gem镜像,地址是http://ruby.taobao.org/  为什么有这个? 由于国内网络原因(你懂的),导致 rubygems. ...

  9. 打造自己的Markdown编辑器

    原文链接:  http://www.errdev.com/post/5/ Markdown以其简洁的语法赢得了广大程序猿的喜爱,搜了一下github上相关的web编辑器,星星比较多的 Stackedi ...

  10. python用法笔记(数组(list、touple、dict)、字符串)

    1.产生n个全为1的数组a=[1]*n2.字符数字转化int('12')float('12.5')str(123.45)ASCII码转为相应的字符:chr(97)字符转化为相应的ASCII码:ord( ...