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 ...
随机推荐
- parse_url等函数
$_SERVER["REQUEST_URI"]://这个可以获取域名后的url,比如/test1/parse_url.php?id=7&name=wuhan 常见用法$ur ...
- Centos中yum方式安装java
查看CentOS自带JDK是否已安装.◆输入:yum list installed |grep java. 若有自带安装的JDK,如何卸载CentOS系统自带Java环境?◆卸载JDK相关文件输入:y ...
- [原创]CI持续集成系统环境---部署Gitlab环境完整记录
Gitlab是一个代码托管平台,在实际工作中,对代码管理十分有用. 废话不多说,下面是对我自己搭建的Gitlab环境做一记录: (1)安装 ------------------------------ ...
- <global-results>
全局result(global-results)有很多时候一个<result>可供很多<action>使用,这时可以使用<global-results>标签来定义全 ...
- RDLC直接打印帮助类
代码 /// <summary> /// 打印帮助类 /// </summary> public class PrintHelper { private int m_curre ...
- Django1.10环境安装
在Ubuntu14上 一 安装脚本 wget https://github.com/django/django/archive/master.tar.gz apt-get install python ...
- c# nullable类型有什么用
可空类型,语法: ; int? inully = 10; Nullable<int> inullx0 = null; int? inully0 ...
- 七种css方式让一个容器水平垂直居中
阅读目录 方法一:position加margin 方法二: diaplay:table-cell 方法三:position加 transform 方法四:flex;align-items: cente ...
- 查询EBS请求日志的位置和名称
select * from FND_CONCURRENT_PROGRAMS_VL fcp where fcp.USER_CONCURRENT_PROGRAM_NAME like '%CUX%XXXX% ...
- java加解密操作过程中的中文乱码问题
import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import ...