cf340 C. Watering Flowers
2 seconds
256 megabytes
standard input
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.
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.
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
2 -1 0 5 3
0 2
5 2
6
4 0 0 5 0
9 4
8 3
-1 0
1 4
33
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的更多相关文章
- Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力
C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...
- Codeforces Round #340 Watering Flowers
题目: http://www.codeforces.com/contest/617/problem/C 自己感觉是挺有新意的一个题目, 乍一看挺难得(= =). 其实比较容易想到的一个笨办法就是:分别 ...
- CodeForces 617C Watering Flowers
无脑暴力题,算出所有点到圆心p1的距离的平方,从小到大排序. 然后暴力枚举p1的半径的平方,计算剩余点中到p2的最大距离的平方,枚举过程中记录答案 #include<cstdio> #in ...
- 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)
题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...
- [Codeforces Round #340 (Div. 2)]
[Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 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 ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
随机推荐
- c# 二进制或算法实现枚举的HasFlag函数
from:http://www.cnblogs.com/icyJ/archive/2013/02/20/HasFlag.html 在权限的管理中,常常会出现一个权限包含的现象.例如,有三种基本权限:职 ...
- .Net core Linux环境安装
10月份的时候在自己电脑上搭了开发环境,当时跑完Welcome后就搁置了一段时间,最近有一个小项目要正式采用core来开发并部署在linux环境下,于是在Linux上也搭建一个运行环境. 虽然不经常使 ...
- spring这么流行的原因是什么
spring这么流行的原因是什么?对象与对象之间的依赖关系不再通过对象去创建对象了,而是通过配置文件来管理他们的依赖关系.这就是spring的依赖注入机制,这个注入关系在一个叫IOC的容器中管理.在这 ...
- 破解windows server 2008 的登录密码。有效的
今天拿到一块以前服务器上替换下来的老盘,里面还有系统.挂载到另外一台闲置服务器,发现密码忘记了, 结果拿出pe和以前修改xp和2003的系统那样去修改发现不行,不知道为什么,修改SAM文件明明提示成功 ...
- Android UI基础之五大布局
Android UI基础之五大布局 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Andro ...
- Object-Oriented CSS
1.指导思想: http://oocss.org/ 2.reset.css http://meyerweb.com/eric/tools/css/reset/ 3.normalize.css http ...
- threejs构建web三维视图入门教程
本文是一篇简单的webGL+threejs构建web三维视图的入门教程,你可以了解到利用threejs创建简单的三维图形,并且控制图形运动.若有不足,欢迎指出. 本文使用的框架是three.js gi ...
- 第二章 Js函数
函数的定义二种定义 ①function myfunc () { console("hello"); }; ②var myfunc = function () { console ...
- QRadioButton分组且无边框的简单实现
最近在用QT+VS2008做一个项目,涉及到一个综合测评表,说白了有点像问卷调查——很多题目每题若干个选项. 初始时打算用下拉框,每个框中填入所有选项,但后来一琢磨这种方式不够直观与人性化,增添了一步 ...
- 制衡技术,从Adblock所想到的
这是一个很特别的东西.可能已经有人发现了它,但是它并非被广泛接受. 对于这个技术的思考来源主要是在安装了Adblock后想到的.这种反作用力的技术,很可能是一片蓝海.而这种技术的产生及推广,对未来社会 ...