Codeforces Round #340 (Div. 2) C
Description
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, - 10^7 ≤ x1, y1, x2, y2 ≤ 10^7) — 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 ( - 10^7 ≤ xi, yi ≤ 10^7) — 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 r1^2 + r2^2. 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 (r1^2 = 5, r2^2 = 1):
The second sample is (r1^2 = 1, r22 = 3^2):
首先,我们保存每一个花坛与两个喷泉的距离(平方),记为r1 r2
我们以其中r1的第一个距离作为开始。开始往后面遍历,如果发现后面有距离超过起始点,说明有没有覆盖的
那么把超过点的放在r2的覆盖的范围内,加起来。遍历完毕取最小值
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x7fffffff
#define INFL 0x7fffffffffffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
pair<LL,LL> q[2002];
int main()
{
LL n,x1,y1,x2,y2;
LL x,y;
cin>>n>>x1>>y1>>x2>>y2;
for(int i=0;i<n;i++)
{
cin>>x>>y;
q[i+1].first=(x-x1)*(x-x1)+(y-y1)*(y-y1);
q[i+1].second=(x-x2)*(x-x2)+(y-y2)*(y-y2);
// cout<<q[i+1].first<<" "<<q[i+1].second<<endl;
}
LL sum=INFL;
for(int i=0;i<=n;i++)
{
LL ans_1,ans_2=0;
ans_1=q[i].first;
// cout<<q[i].first<<"A"<<endl;
for(int j=1;j<=n;j++)
{
if(q[j].first>ans_1)
{
ans_2=max(ans_2,q[j].second);
}
}
// cout<<ans_2<<"B"<<endl;
// cout<<ans_1+ans_2<<"C"<<endl;
sum=min(sum,ans_1+ans_2);
// cout<<sum<<"C"<<endl;
}
cout<<sum<<endl;
return 0;
}
Codeforces Round #340 (Div. 2) C的更多相关文章
- [Codeforces Round #340 (Div. 2)]
[Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...
- 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 ...
- 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 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)
题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...
- 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 ...
- 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 ...
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number (莫队)
题目链接:http://codeforces.com/contest/617/problem/E 题目大意:有n个数和m次查询,每次查询区间[l, r]问满足ai ^ ai+1 ^ ... ^ aj ...
随机推荐
- python爬虫(8)--Xpath语法与lxml库
1.XPath语法 XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历.XPath 是 W3C XSLT 标准的主要元素,并且 XQuery ...
- 《Android应用性能优化》 第6章 性能评测和剖析
1.时间测量 System.currentTimeMillis 精读和准确度可能不够:更改系统时间会影响结果:UTC时间1970/1/1 00:00:00到现在的毫秒数 System.nanoTime ...
- newcoder中的基础题
1. mysql_num_fields() 函数返回结果集中字段的数 2. <?php class A{ ; } $a = new A(); $b = $a; $a; echo $b-> ...
- FactoryMethodPattern(23种设计模式之一)
设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...
- IDEA工作中常用快捷键
ctrl+shift+t: Ubuntu中在一个工具栏中打开两个终端 shift+shift: 搜索任何类 ctrl+N: 搜索任何类 ctrl+right: forward----自定义 ctrl+ ...
- SDUT 3404 数据结构实验之排序七:选课名单.!?
数据结构实验之排序七:选课名单 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 随着学校规模 ...
- HDU 5373 The shortest problem (数学)
题意:给定两个数的n和m,有一种操作,把 n 的各位数字加起来放到 n后面形成一个新数n,问重复 m 次所得的数能否整除 11. 析:这个题首先要知道一个规律奇数位的和减去偶数位的和能被11整除的数字 ...
- UC浏览器体验
1.用户界面: 有两个页面,一个展示网页应用-可添加自己喜欢的网页应用,另一个用来搜索,有推荐的常用的网址,有UC头条,页面下有设置,整体布局常规 2.短期刺激: 没有特别花哨的地方:个人感觉比较实用 ...
- html颜色设定 - 网址不见了看这里
- Mysql 5.6主从搭建
mysql设置主从的重要性和必要性不必多说,下面开始详细说明如何搭建主从. 1.主服务器上创建一个用于复制的账户. mysql'; mysql> flush privileges; 2.主服务器 ...