Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力
2016-01-25 00:05
337 查看
C. Watering Flowers
题目连接:
http://www.codeforces.com/contest/617/problem/CDescriptionww.co
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 Input
2 -1 0 5 30 2
5 2
Sample Output
6Hint
题意
有一个花园,有两个喷水龙头,你需要浇灌花园里面所有的花两个喷水龙头的喷水半径分别是r1,r2
你需要使得r1*r1+r2*r2最小
请问是多少
题解:
将其中一维排序,然后另外一维直接取剩下的最大值就好了代码
#include<bits/stdc++.h> using namespace std; struct node { long long x,y; }; node p[2]; node point[2005]; long long pre[2005]; bool cmp(node a,node b) { if(a.x==b.x)return a.y<b.y; return a.x<b.x; } int main() { int n;scanf("%d",&n); for(int i=0;i<2;i++) scanf("%lld%lld",&p[i].x,&p[i].y); for(int i=1;i<=n;i++) { long long x,y; scanf("%lld%lld",&x,&y); point[i].x = (x-p[0].x)*(x-p[0].x)+(y-p[0].y)*(y-p[0].y); point[i].y = (y-p[1].y)*(y-p[1].y)+(x-p[1].x)*(x-p[1].x); } sort(point+1,point+1+n,cmp); for(int i=n;i>=1;i--) pre[i]=max(pre[i+1],point[i].y); long long ans = pre[1]; for(int i=1;i<=n;i++) ans = min(ans,point[i].x+pre[i+1]); cout<<ans<<endl; }
相关文章推荐
- [工作中的设计模式]桥接模式bridge
- Qt绘图2
- 阿里巴巴发布第一颗自研芯片,全球最强 AI 芯片含光 800
- Spring Boot 动态数据源示例(多数据源自动切换)
- 21行Python代码实现拼写检查器
- 基于Python Shell获取hostname和fqdn释疑
- 谈谈Python进行验证码识别的一些想法
- Python网站验证码识别
- 详解Python验证码识别
- Python开发如何在ubuntu 15.10 上配置vim
- Python编程中对文件和存储器的读写示例
- python黑魔法之编码转换
- php代码架构的八点注意事项
- PHP几个实用自定义函数小结
- php结合md5实现的加密解密方法
- win7安装php框架Yii的方法
- crontab无法执行php的解决方法
- 基于命令行执行带参数的php脚本并取得参数的方法
- PHP设置头信息及取得返回头信息的方法
- PHP实现的oracle分页函数实例