codeforces 352 div 2 C.Recycling Bottles 贪心
2016-05-14 20:31
411 查看
C. Recycling Bottles
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
First line of the input contains six integers ax, ay, bx, by, tx and ty (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 integers xi and yi (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.
Output
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 exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if
.
Examples
input
output
input
output
Note
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.
题意:给你两个人,一个垃圾桶;利用人把垃圾全部进桶,使得距离最短;
思路:显然答案是sigma一个垃圾到垃圾桶距离的两倍;
求出一个人动和两个人动的差值最大的距离;
比较减去最大值;
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
First line of the input contains six integers ax, ay, bx, by, tx and ty (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 integers xi and yi (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.
Output
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 exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if
.
Examples
input
3 1 1 2 0 0 3 1 1 2 1 2 3
output
11.084259940083
input
5 0 4 2 2 0 5 5 2 3 0 5 5 3 5 3 3
output
33.121375178000
Note
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.
题意:给你两个人,一个垃圾桶;利用人把垃圾全部进桶,使得距离最短;
思路:显然答案是sigma一个垃圾到垃圾桶距离的两倍;
求出一个人动和两个人动的差值最大的距离;
比较减去最大值;
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define inf 999999999 #define esp 0.00000000001 //#pragma comment(linker, "/STACK:102400000,102400000") int scan() { int res = 0 , ch ; while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) ) { if( ch == EOF ) return 1 << 30 ; } res = ch - '0' ; while( ( ch = getchar() ) >= '0' && ch <= '9' ) res = res * 10 + ( ch - '0' ) ; return res ; } long double dis(long double a,long double b,long double c,long double d) { return sqrt((d-b)*(d-b)+(c-a)*(c-a)); } struct is { long double cha; int pos; }a1[100010],b1[100010]; int flag[100010]; bool cmp(is x,is y) { return x.cha>y.cha; } int main() { long double a,b,c,d,e,f; cin>>a>>b>>c>>d>>e>>f; long double sum=0; int x; scanf("%d",&x); for(int i=0;i<x;i++) { long double u,v; cin>>u>>v; sum+=dis(e,f,u,v)*2.0; a1[i].cha=dis(e,f,u,v)-dis(u,v,a,b); b1[i].cha=dis(e,f,u,v)-dis(u,v,c,d); a1[i].pos=i; b1[i].pos=i; } if(x==1) { //printf("%f\n",sum-max(a1[0].cha,b1[0].cha)); cout << setprecision(6) << setiosflags(ios::scientific)<<sum-max(a1[0].cha,b1[0].cha)<<endl; return 0; } sort(a1,a1+x,cmp); sort(b1,b1+x,cmp); double aa,bb; if(a1[0].cha<0&&b1[0].cha<0) { cout << setprecision(6) << setiosflags(ios::scientific)<<sum-max(a1[0].cha,b1[0].cha)<<endl; return 0; } long double ans1; long double ans2; long double ans3; if(a1[0].pos!=b1[0].pos) ans3=a1[0].cha+b1[0].cha; else { if(a1[0].cha+b1[1].cha<a1[1].cha+b1[0].cha) ans3=a1[1].cha+b1[0].cha; else ans3=a1[0].cha+b1[1].cha; } ans2=a1[0].cha; ans1=b1[0].cha; cout << setprecision(6) << setiosflags(ios::scientific)<<sum-max(ans1,max(ans2,ans3))<<endl; return 0; }
相关文章推荐
- Lucene 初探
- 自动布局的一些笔记
- bestcoder百度之星2016AK 1001&1002&1003&1004 题解
- Python:no encoding declared 错误
- File类
- JS学习笔记
- iOS 并行编程:NSOperation Queues
- 1094. The Largest Generation (25)【二叉树】——PAT (Advanced Level) Practise
- 【caffe配置】在vs2013用已经训练好的Alexnet网络提取fc6特征
- iOS开发 - 第02篇 - UI进阶 - 03 - TableView Cell
- Ubuntu下IntelliJ IDEA新建Java Web项目
- Android并发编程之白话文详解Future,FutureTask和Callable
- [置顶] 字符串的反转
- HYSBZ 1036 树的统计Count 树链剖分
- Git与Repo入门
- 第十周项目5——摩托车继承自行车和机动车
- SSH网上答题系统质量属性
- 1093. Count PAT's (25)【计数】——PAT (Advanced Level) Practise
- 说反话
- QT-如何添加资源文件