Codeforces Round #340 (Div. 2)C. Watering Flowers(暴力)
2016-03-07 09:02
387 查看
题意:在笛卡尔坐标系中给出n个点和两个圆心坐标,以两个点为圆心画圆,要求所画的圆能够覆盖坐标系内所有的点,求r1^2+r2^2的最小值;
思路:先计算出所有点到第一个圆心的距离,然后以此为半径,直接枚举。需要注意的是范围大于int
思路:先计算出所有点到第一个圆心的距离,然后以此为半径,直接枚举。需要注意的是范围大于int
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<queue> using namespace std; typedef long long ll; const ll INF=1e18; const int maxn=2005; int n,x1,y1,x2,y2; struct Point{ ll x,y; ll dis1; ll dis2; }point[maxn]; ll getDis1(ll x,ll y){ return (x-x1)*(x-x1)+(y-y1)*(y-y1); } ll getDis2(ll x,ll y){ return (x-x2)*(x-x2)+(y-y2)*(y-y2); } int main(){ while(~scanf("%d%d%d%d%d",&n,&x1,&y1,&x2,&y2)){ for(int i=1;i<=n;i++){ scanf("%I64d%I64d",&point[i].x,&point[i].y); point[i].dis1=getDis1(point[i].x,point[i].y); point[i].dis2=getDis2(point[i].x,point[i].y); } point[0].dis1=point[0].dis2=0; ll ans=INF; ll r1=0,r2=0; for(int i=0;i<=n;i++){ r1=point[i].dis1; r2=0; for(int j=1;j<=n;j++){ if(point[j].dis1<=r1) continue; if(point[j].dis2>r2) r2=point[j].dis2; } ans=min(ans,r1+r2); } if(n==1) ans=min(point[1].dis1,point[1].dis2); printf("%I64d\n",ans); } return 0; }
相关文章推荐
- Oracle中"行转列"的实现方式
- SQL常用语句
- 802.15.4中文版
- 学习MySQL基本操作比较好的文章
- jQuery之前端国际化jQuery.i18n.properties
- Yii2中自带分页类实现分页
- hihocoder-建造基地(完全背包)
- EVC编程与调试过程出现的问题
- ExtJs.Store.load()各参数含义解析
- Python Sokcet 文档翻译
- 云计算
- 网络编程nagle算法和TCP_NODELAY
- 简洁的序列预测算法
- halcon-周期性噪声去除
- 出现监听错误
- poj 1182 食物链(DSU)
- ExtJs.Store.load()各参数含义解析
- C/C++从文件末尾反向获取指定N行数据
- 自我介绍
- Windows CE创建桌面快捷方式