Codeforces Round #352 (Div. 1) A. Recycling Bottles
来源:互联网 发布:淘宝没发票可以投诉吗 编辑:程序博客网 时间:2024/05/29 04:42
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position(xi, yi). Both Adil and Bera can carry only one bottle at once each.
For both Adil and Bera the process looks as follows:
- Choose to stop or to continue to collect bottles.
- If the choice was to continue then choose some bottle and walk towards it.
- Pick this bottle and walk to the recycling bin.
- Go to step 1.
Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.
They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.
First line of the input contains six integers ax,ay,bx,by,tx andty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains two integersxi andyi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle.
It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury isb. The checker program will consider your answer correct if.
3 1 1 2 0 031 12 12 3
11.084259940083
5 0 4 2 2 055 23 05 53 53 3
33.121375178000
Consider the first sample.
Adil will use the following path: .
Bera will use the following path: .
Adil's path will be units long, while Bera's path will be units long.
分析:很容易错的一道题,注意特判n == 1的情况,因为我写法的问题所有最后导致n == 2时也出错了。。。
#include <cstdio>#include <iostream>#include <unordered_map>#include <algorithm>using namespace std;double tot;long long n,ma1,ma2,mb1,mb2,ax,ay,bx,by,tx,ty,x[100005],y[100005];double got(int i,long long X,long long Y){if(i == 0) return 2147483648;return sqrt((x[i] - X)*(x[i] - X) + (y[i] - Y)*(y[i] - Y)) - sqrt((x[i] - tx)*(x[i] - tx) + (y[i] - ty)*(y[i] - ty));}int main(){scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);scanf("%d",&n);for(int i = 1;i <= n;i++) {scanf("%I64d %I64d",&x[i],&y[i]);if(got(i,ax,ay) < got(ma2,ax,ay)) ma2 = i;if(got(ma2,ax,ay) < got(ma1,ax,ay)) swap(ma1,ma2);if(got(i,bx,by) < got(mb2,bx,by)) mb2 = i;if(got(mb2,bx,by) < got(mb1,bx,by)) swap(mb1,mb2);tot += 2*sqrt((x[i] - tx)*(x[i] - tx) + (y[i] - ty)*(y[i] - ty)); }double ans1 = tot + min(got(ma1,ax,ay),got(mb1,bx,by)),ans2 = 2147483648;if(ma1 != mb1) ans2 = tot + got(ma1,ax,ay) + got(mb1,bx,by);else ans2 = tot + min(got(ma1,ax,ay) + got(mb2,bx,by),got(ma2,ax,ay) + got(mb1,bx,by));if(n != 1) printf("%.12lf",min(ans1,ans2));else printf("%.12lf",ans1);}
- Codeforces Round #352 (Div. 1) A. Recycling Bottles
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
- Codeforces 672 C. Recycling Bottles(Codeforces Round #352 (Div. 2))
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
- Codeforces Round #352 (Div. 2) C - Recycling Bottles
- Codeforces Round #352 (Div. 2)C. Recycling Bottles
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
- Codeforces Round #352 (Div. 2) C. Recycling Bottles (几何)
- Codeforces #352 Recycling Bottles
- Codeforces Round #352 (Div. 2) C. Recycling Bottles __ geometry, greedy and pretreat
- Codeforces 671A Recycling Bottles
- codeforces 671A Recycling Bottles
- CodeForces 671A Recycling Bottles
- CodeForces Round 352——Recycling Bottles & Robin Hood
- Codeforces 671A Recycling Bottles 【dp】
- 【模拟】Codeforces 671A Recycling Bottles
- 排序-快速排序(c)
- 【HUSTOJ】1114: 高精度加法之二
- 优化SQL Server数据库的50种方法
- Codeforces Round #352 (Div. 1) B. Robin Hood
- Linux(CentOS)安装SVN服务端
- Codeforces Round #352 (Div. 1) A. Recycling Bottles
- Android 引入aar相关问题
- 【Qt】标准颜色对话框类
- 关于HashSet与HashMap
- iOS开发设置textFiled的placeholder颜色
- Activity四种启动模式
- 常量字符串为什么位于静态存储区?
- 百度地图离线开发包
- LeetCode:Top K Frequent Elements