CodeForces-672C-Recycling Bottles
来源:互联网 发布:学网络营销好还是java 编辑:程序博客网 时间:2024/06/08 12:24
给你A,B,C三个点的坐标,C表示垃圾桶,A,B表示人
在给你n个垃圾的坐标,问你两人每次最多可以携带一个垃圾到达垃圾桶
将这n个垃圾全部扔进垃圾桶最少走多少路
这里n个垃圾可以完全由其中一个或两个人捡起
在人到达C后,我们知道之后这个人捡垃圾都是从C到垃圾距离*2
我们假设所有垃圾都是从C出发捡的
1.a和b均休息时,此时必须让a或b继续捡垃圾,虽然此时两人捡垃圾都只能令sum增大,但只能选取相对令sum增大较小的人捡。
2.a和b选择了相同垃圾捡取,只需计算出a能使总路程最短的垃圾ak1与次短ak2,与相应的bk1与bk2。此时ak1=bk1,那么令a选择ak2或者b选择bk2,比较哪种能令路程更短,则选择哪种。
Description
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 .
Sample Input
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
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#define maxn 100100using namespace std;double dist(double a,double b,double c,double d){ return sqrt((a-c)*(a-c)+(b-d)*(b-d));}double disa[maxn];double disb[maxn];double dis[maxn];double disk[maxn];double Min1,Min2,ans;int main(){ double a,b,c,d,e,f; int n; double x,y; while(cin>>a>>b>>c>>d>>e>>f>>n){ double sum=0; for(int i=1;i<=n;i++){ scanf("%lf %lf",&x,&y); disa[i]=dist(a,b,x,y); disb[i]=dist(c,d,x,y); dis[i]=dist(e,f,x,y); sum+=dis[i]; } sum*=2.0; Min1=Min2=1e19; for(int i=1;i<=n;i++){ Min1=min(Min1,disa[i]-dis[i]); Min2=min(Min2,disb[i]-dis[i]); } ans=min(sum+Min1,sum+Min2);//当有一个不动的时候 int id1=-1,id2=-1; Min1=Min2=1e19; for(int i=1;i<=n;i++){ if(disb[i]-dis[i]<Min1){ Min1=disb[i]-dis[i]; id1=i; } } for(int i=1;i<=n;i++){ if(disa[i]-dis[i]<Min2&&(id1!=i)){ Min2=disa[i]-dis[i]; id2=i; } } ans=min(ans,sum+Min1+Min2); Min1=Min2=1e19; for(int i=1;i<=n;i++){ if(disa[i]-dis[i]<Min1){ Min1=disa[i]-dis[i]; id1=i; } } for(int i=1;i<=n;i++){ if(disb[i]-dis[i]<Min2&&(id1!=i)){ Min2=disb[i]-dis[i]; id2=i; } } ans=min(ans,sum+Min1+Min2); printf("%.10f\n",ans); } return 0;}
- codeforces 672C. Recycling Bottles
- CodeForces-672C-Recycling Bottles
- codeforces 672C Recycling Bottles
- Codeforces 672C Recycling Bottles (YY)
- codeforces 672C Recycling Bottles (枚举+贪心)
- CodeForces - 672C Recycling Bottles (贪心)
- 【18.69%】【codeforces 672C】Recycling Bottles
- Codeforces 672C Recycling Bottles 几何+贪心
- Codeforces 672 C. Recycling Bottles(Codeforces Round #352 (Div. 2))
- Codeforces 672C Recycling Bottles【极限思维+贪心枚举】
- Codeforces #352 Div2 C Recycling Bottles
- codeforces#352-C - Recycling Bottles-贪心
- Codeforces #352 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
- springMVC开源作业调度框架--quartz
- 利用jacob实现access数据访问
- 最全面的java多线程用法解析
- vickate_iOS_UITextField 的占位符自定义设置
- Box2D C++ 教程-自定义重力
- CodeForces-672C-Recycling Bottles
- 23种设计模式(15)--State模式
- 盘点最实用的大数据可视化分析工具(1/4)
- 跟谷歌学一个多次点击事件的逻辑处理
- Box2D C++ 教程-匀速运动
- >>> FilterDispatcher <<< is deprecated! Please use the new filters!
- 我们应当怎样学习HTML和CSS
- STM32F207 USART+DMA代码+个人理解
- Box2D C++ 教程-旋转到指定角度