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 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 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 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32):

思路:直接枚举就可以了,r1可以是0或者是到其他任意一个点的距离,然后就枚举r2,条件是到1的距离大于r1中最大,

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const long long INF = 10e18;
const int MAX = + ;
long long Distance1[MAX],Distance2[MAX];
long long get_distance(long long x1,long long y1,long long x2, long long y2)
{
return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
}
int main()
{
int n;
long long x1,x2,y1,y2,x,y;
long long r1 = ,r2 = ;
long long ans = INF;
scanf("%d%I64d%I64d%I64d%I64d", &n,&x1,&y1,&x2,&y2);
Distance1[] = Distance2[] = ;
for(int i = ; i <= n; i++)
{
scanf("%I64d%I64d",&x,&y);
Distance1[i] = get_distance(x1,y1,x,y);
Distance2[i] = get_distance(x2,y2,x,y);
} for(int i = ; i <= n; i++)
{
r1 = Distance1[i];
r2 = ;
for(int j = ; j <= n; j++)
{
if(Distance1[j] > r1 && Distance2[j] > r2)
{
r2 = Distance2[j];
}
}
ans = min(ans, r1 + r2);
} printf("%I64d\n",ans);
return ;
}

cf340 C. Watering Flowers的更多相关文章

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

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

  2. Codeforces Round #340 Watering Flowers

    题目: http://www.codeforces.com/contest/617/problem/C 自己感觉是挺有新意的一个题目, 乍一看挺难得(= =). 其实比较容易想到的一个笨办法就是:分别 ...

  3. CodeForces 617C Watering Flowers

    无脑暴力题,算出所有点到圆心p1的距离的平方,从小到大排序. 然后暴力枚举p1的半径的平方,计算剩余点中到p2的最大距离的平方,枚举过程中记录答案 #include<cstdio> #in ...

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

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

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

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

  6. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  7. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  8. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  9. poj1157LITTLE SHOP OF FLOWERS

    Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...

随机推荐

  1. CSS 布局调试工具

    说是工具其实只是一段 Javascript 代码,但非常实用,它会给页面里所有的 DOM 元素添加一个 1px 的描边(outline),方便我们在调试 CSS 过程中分析.排查问题. 先来看看代码, ...

  2. JQuery判断数组中是否包含某个元素$.inArray("js", arr);

    var arr = [ "xml", "html", "css", "js" ];   $.inArray(" ...

  3. 用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(2)-- 画点

    [概览] 本文实现如下的程序:(在窗体中绘画出[-100, 100]两个周期的正弦函数图像) 主要步骤如下: 1.在eric6中新建项目,新建窗体 2.(自动打开)进入PyQt5 Desinger,编 ...

  4. 即学即会 Java 程序设计基础视频教程(100课整)无水印版

    课程总共包含100个课时,总授课长达27多个小时,内容覆盖面广,从入门到精通,授课通俗易懂,分析问题独到精辟通过本套视频的学习,学员能够快速的掌握java编程语言,成为java高手. 课程目录:课时1 ...

  5. Caffe学习系列(15):计算图片数据的均值

    图片减去均值后,再进行训练和测试,会提高速度和精度.因此,一般在各种模型中都会有这个操作. 那么这个均值怎么来的呢,实际上就是计算所有训练样本的平均值,计算出来后,保存为一个均值文件,在以后的测试中, ...

  6. File的保存与读取

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...

  7. [CareerCup] 13.10 Allocate a 2D Array 分配一个二维数组

    13.10 Write a function in C called my2DAlloc which allocates a two-dimensional array. Minimize the n ...

  8. PRML读书会第四章 Linear Models for Classification(贝叶斯marginalization、Fisher线性判别、感知机、概率生成和判别模型、逻辑回归)

    主讲人 planktonli planktonli(1027753147) 19:52:28 现在我们就开始讲第四章,第四章的内容是关于 线性分类模型,主要内容有四点:1) Fisher准则的分类,以 ...

  9. 与Python Falling In Love_Python跨台阶(环境搭建)

    Python--环境搭建 首先需要下载python安装包,官网下载地址:https://www.python.org/downloads/ 下载完直接点击安装... 安装完后就可以配置环境变量咯^_^ ...

  10. python的闭包与装饰器

    原文发表在我的博客主页,转载请注明出处 前言 如果把python当作脚本语言,每次就是写个几十行上百行来处理数据的话,装饰器也许不是很必要,但是如果要开发一个大型系统,装饰器是躲不开的,最开始体会ry ...