Codeforces Round #340 (Div. 2)-C. Watering Flowers
来源:互联网 发布:php支付宝sdk集成 编辑:程序博客网 时间:2024/05/18 01:56
原题链接
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 30 25 2
6
4 0 0 5 09 48 3-1 01 4
33
算出每一朵花到第一个喷泉的距离,再把每朵花按照距离排序,从大到小遍历每个距离,当作第一个喷泉的r1^2, 在算出剩下的花和第二个喷泉的距离,取最大值,当作第二个喷泉的r2^2
#include <bits/stdc++.h>#define maxn 2005using namespace std;typedef long long ll;struct Node{bool friend operator < (const Node&a, const Node&b){return a.d1 < b.d1;}ll x, y;ll d1, d2;}node[maxn];int main(){//freopen("in.txt", "r", stdin);int n;ll x1, y1, x2, y2;scanf("%d%I64d%I64d%I64d%I64d", &n, &x1, &y1, &x2, &y2);for(int i = 1; i <= n; i++){ scanf("%I64d%I64d", &node[i].x, &node[i].y); node[i].d1 = (node[i].x - x1) * (node[i].x - x1) + (node[i].y - y1) * (node[i].y - y1); } sort(node+1, node+n+1); ll ans = 1e18; for(int i = n; i >= 0; i--){ node[i].d2 = (node[i].x - x2) * (node[i].x - x2) + (node[i].y - y2) * (node[i].y - y2); node[i].d2 = max(node[i].d2, node[i+1].d2); ans = min(ans, node[i].d1 + node[i+1].d2); } printf("%I64d\n", ans); return 0;}
- Codeforces Round #340 (Div. 2) C. Watering Flowers
- Codeforces Round #340 (Div. 2) C. Watering Flowers
- Codeforces Round #340 (Div. 2)C. Watering Flowers
- Codeforces Round #340 (Div. 2)C. Watering Flowers(暴力)
- Codeforces Round #340 (Div. 2)C. Watering Flowers
- Codeforces Round #340 (Div. 2)-C. Watering Flowers
- Codeforces 617C Watering Flowers (Round #340 (Div. 2) C题) nlogn算法
- Codeforces Round #340 (Div. 2) 617C Watering Flowers(计算几何)
- Codeforces Round #340 (Div. 2) C. Watering Flowers(暴力枚举)
- Codeforces Round #340 (Div. 2) C. Watering Flowers 计算几何、圆和点
- Codeforces Round #340 -C - Watering Flowers-暴力+set
- 【Codeforces Round 340 (Div 2)C】【暴力排序枚举】Watering Flowers 2个灌溉器灌溉所有点最小的rr+RR
- Codeforces 617 C. Watering Flowers
- Codeforces 617C:Watering Flowers
- Codeforces 617C(Watering Flowers)
- CodeForces 617C Watering Flowers
- Codeforces Round #341 (Div. 2) C. Wet Shark and Flowers
- Codeforces Round #341 (Div. 2)--C. Wet Shark and Flowers
- 对极几何基本概念
- codeforces 373div1 Sasha and Array 矩阵+线段树
- 计算机网络概述
- dispatcherServlet,HandlerMapping,HandlerAdapter
- 【机器学习】Learning to Rank之Ranking SVM 简介
- Codeforces Round #340 (Div. 2)-C. Watering Flowers
- 从1开始学习java一个月后总结心得
- 平方数
- angular $resource模块
- c++没有垃圾回收机制的原因
- Java递归实现树状结构
- 在Dubbo中开发REST风格的远程调用(RESTful Remoting)
- 212. Word Search II (DFS,trie)
- centos 7 安装mysql5.7