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 ...
随机推荐
- win PPTP场景与搭建
远程访问方案: 1,端口映射 2,vpn 实现这种远程访问的协议:pptp 等. 场景: 要从考试服务器[电信]下载题目. 单位有两个办事处,A双出口,B单网通出口. B要下载题,很慢. ...
- JavaScript及其异步实现续:Promise让一切更简单
在写这篇文章之前,我参考了以下文章.所以我文中的例子都是精准的,而且有循可依.下面抛出例子的链接: Understanding JQuery.Deferred and Promise Deferred ...
- [git]图解git常用命令
本文图解git中最常用的命令.如果你稍微理解git的工作原理,这篇文章能够让你理解的更透彻. 基本用法 约定 命令详解 Diff Commit Checkout Detached HEAD(匿名分支提 ...
- http状态码代表含义
状态代码 状态信息 含义 100 Continue 初始的请求已经接受,客户应当继续发送请求的其余部分.(HTTP 1.1新) 101 Switching Protocols 服务器将遵从客户的请求转 ...
- [NOIP2016-day1-T2]天天爱跑步running_题解
题目来源:http://www.lydsy.com/JudgeOnline/problem.php?id=4719 镇楼图: noip滚粗后..订正的第一题. 题目大意: 有若干条路径在一棵树上,问每 ...
- windows7设置java的环境变量
win7 下配置 java 环境变量 首先,你应该已经安装了 java 的 JDK 了,笔者安装的是:jdk-7u7-windows-x64 接下来主要讲怎么配置 java 的环境变量,也是为了以 ...
- 集DDD,TDD,SOLID,MVVM,DI,EF,Angularjs等于一身的.NET(C#)开源可扩展电商系统–Virto Commerce
今天一大早来看到园友分享的福利<分享一个前后端分离方案源码-前端angularjs+requirejs+dhtmlx 后端asp.net webapi>,我也来分享一个吧.以下内容由笔者写 ...
- 【MPI学习5】MPI并行程序设计模式:组通信MPI程序设计
相关章节:第13章组通信MPI程序设计. MPI组通信与点到点通信的一个重要区别就是:组通信需要特定组内所有成员参与,而点对点通信只涉及到发送方和接收方. 由于需要组内所有成员参与,因此也是一种比较复 ...
- activity动画主题使用注意事项
当我们不满足于系统默认的activity动画交互方式,我们可以通过在主题里面,指定activity动画样式来实现自定义交互效果. 在style里面定义样式 <!-- Base applicati ...
- IT男的”幸福”生活"续4
翻来翻去,总是睡不觉.大脑口一堆问题.一个又冒出一个,没完没了.明天该怎样去进行下一步呢.. ….. 夜一下子深黑很多,窗外的公路,时而有货车通过,动不动按喇叭,而我住在二楼,真它的吵.也许她住在五楼 ...