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的覆盖的范围内,加起来。遍历完毕取最小值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #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; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~