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. Yii系列教程(二):功能简介

    1 MVC架构 1.1处理流程 一个Web请求在Yii内部的执行流程如下图所示: 1.2组件角色 组件名 角色与责任 index.php 入口脚本.创建Application的单例对象. applic ...

  2. php动态生成一个xml文件供swf调用

    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdo ...

  3. windows下mysql5.7安装及配置

    装完msi后,复制my-default.ini文件,黏贴为my.ini文件,内容修改如下: # For advice on how to change settings please see# htt ...

  4. Cocos2d-x FlappyBird

    HelloWorldScene.cpp #include "HelloWorldScene.h" USING_NS_CC; CCScene* HelloWorld::scene() ...

  5. Spring的Bean的作用域

    singleton: * IOC中只存在一个共享的Bean实例,并且所有对bean的请求,只要id与该bean定义相匹配,则只会返回bean的同一实例 *  与单例模式区别:单例设计模式表示一个Cla ...

  6. codejam环境熟悉—Minimum Scalar Product

    今天准备熟悉一下codejam的在线编程,为google的笔试做准备,因此按照codejam上对新手的建议,先用了一个简单的题目来弄清楚流程.记录一下需要注意的地方.   1.输入输出 输入输出重定位 ...

  7. 分析fork后多进程对文件的共享

    fork函数是创建一个新的进程作为原进程的子进程,创建的子进程和父进程存在很多的相似性,首先父子进程的虚拟存储空间的用户空间是相同的,是将父进程的拷贝给子进程.同时父子进程对文件的操作是共享方式.因为 ...

  8. Hadoop第三天---分布式文件系统HDFS(大数据存储实战)

    1.开机启动Hadoop,输入命令:  检查相关进程的启动情况: 2.对Hadoop集群做一个测试:   可以看到新建的test1.txt和test2.txt已经成功地拷贝到节点上(伪分布式只有一个节 ...

  9. 基于AWS的自动化部署实践

    过年前,我给InfoQ写了篇文章详细介绍我们团队在过去4年基于AWS的自动化部署实践.文章包括了:为什么选择AWS.AWS上自动化部署的优势和挑战.我们的解决方案,以及和AWS DevOps方案(Op ...

  10. T-SQL 批处理

    批处理简介 批处理是作为一个逻辑单元的T-SQL语句.如果一条语句不能通过语法分析,那么不会运行任何语句.如果一条语句在运行时失败,那么产生错误的语句之前的语句都已经运行了. 为了将一个脚本分为多个批 ...