题目链接:

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:

  1. Choose to stop or to continue to collect bottles.
  2. If the choice was to continue then choose some bottle and walk towards it.
  3. Pick this bottle and walk to the recycling bin.
  4. 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 axaybxbytx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 10^9) — 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 ≤ 10^9) — 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
  1. 3 1 1 2 0 0
    3
    1 1
    2 1
    2 3
output
  1. 11.084259940083
input
  1. 5 0 4 2 2 0
    5
    5 2
    3 0
    5 5
    3 5
    3 3
output
  1. 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.

题意:

给出两个人的初始位置和垃圾桶的位置以及那些瓶子的位置,每个人可以按上面给的步骤进行,问最后两个人走的最少的距离是多少;

思路:

把每个瓶子到垃圾桶和两个人的距离都求出来,再贪心找到最小距离;

最小距离的基础是每个瓶子到垃圾桶距离和的2倍即sum=Σdis[i],然后再选择一个人或者两个人去捡一个瓶子使sum-dis[i]+disa[i]-dis[j]+disb[j]最小,当然这是两个人都去捡的情况,还有就是一个人去捡的情况sum-dis[i]+(disa[i]ordisb[i]);

反正就是找最小的值啦;

本来思路是对的,比赛的时候代码有个地方是b的我直接把a的复制过去忘记改成b了,最后挂在了st上了;

AC代码:

  1. #include <bits/stdc++.h>
  2. /*#include <iostream>
  3. #include <queue>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <algorithm>
  7. #include <cstdio>
  8. */
  9. using namespace std;
  10. #define Riep(n) for(int i=1;i<=n;i++)
  11. #define Riop(n) for(int i=0;i<n;i++)
  12. #define Rjep(n) for(int j=1;j<=n;j++)
  13. #define Rjop(n) for(int j=0;j<n;j++)
  14. #define mst(ss,b) memset(ss,b,sizeof(ss));
  15. typedef long long LL;
  16. const LL mod=1e9+;
  17. const double PI=acos(-1.0);
  18. const int inf=0x3f3f3f3f;
  19. const int N=1e5+;
  20. double fun(double xx,double yy,double fx,double fy)
  21. {
  22. return sqrt((xx-fx)*(xx-fx)+(yy-fy)*(yy-fy));
  23. }
  24. double ax,ay,bx,by,tx,ty,x[N],y[N],dis[N],disa[N],disb[N];
  25. int n;
  26. int main()
  27. {
  28. scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);
  29. scanf("%d",&n);
  30. double ans=;
  31. Riep(n)
  32. {
  33. scanf("%lf%lf",&x[i],&y[i]);
  34. dis[i]=fun(x[i],y[i],tx,ty);
  35. disa[i]=fun(x[i],y[i],ax,ay);
  36. disb[i]=fun(x[i],y[i],bx,by);
  37. ans+=*dis[i];
  38. }
  39. disa[]=;
  40. disb[]=;
  41. dis[]=;
  42. double mmina=,mminb=,s=ans;
  43. int posa=,posb=;
  44. for(int i=;i<=n;i++)
  45. {
  46. if(disa[i]-dis[i]<mmina)
  47. {
  48. mmina=disa[i]-dis[i];
  49. posa=i;
  50. }
  51. if(disb[i]-dis[i]<mminb)
  52. {
  53. mminb=disb[i]-dis[i];
  54. posb=i;
  55. }
  56. }
  57. if(mmina<&&mminb<)
  58. {
  59. if(posa==posb)
  60. {
  61. for(int i=;i<=n;i++)
  62. {
  63. if(i!=posa)
  64. s=min(s,ans-dis[posa]+disa[posa]-dis[i]+disb[i]);
  65. }
  66. for(int i=;i<=n;i++)
  67. {
  68. if(i!=posb)
  69. s=min(s,ans-dis[posb]+disb[posb]-dis[i]+disa[i]);
  70. }
  71. }
  72. else
  73. {
  74. s=ans+mmina+mminb;
  75. }
  76. }
  77. else
  78. {
  79. if(mmina<mminb)
  80. {
  81. s=ans-dis[posa]+disa[posa];
  82. }
  83. else
  84. {
  85. s=ans-dis[posb]+disb[posb];
  86. }
  87. }
  88. printf("%.10lf\n",s);
  89. return ;
  90. }

codeforces 672C C. Recycling Bottles(计算几何)的更多相关文章

  1. 【18.69%】【codeforces 672C】Recycling Bottles

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. Codeforces 671 A——Recycling Bottles——————【思维题】

     Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. CF671A Recycling Bottles 计算几何

    It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can ...

  4. Codeforces Recycling Bottles 模拟

    C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...

  5. Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力

    A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...

  6. CF 672C Recycling Bottles[最优次优 贪心]

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Codeforces Round #352 (Div. 2) C. Recycling Bottles 贪心

    C. Recycling Bottles   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Centr ...

  8. codeforces 352 div 2 C.Recycling Bottles 贪心

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #352 (Div. 2) C. Recycling Bottles

      C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. Python入门--11--自定义函数

    使用def定义自定义函数 举个栗子: def myfristFunction(): print "we are 伐木累!" #输入myfristFunction() 会输出:we ...

  2. Linux 下MySQL 安装与卸载

    这个写的比较好:http://www.cnblogs.com/starof/p/4680083.html 2.卸载系统自带的Mariadb rpm -qa|grep mariadb         / ...

  3. golang sort包 排序

    []float64: ls := sort.Float64Slice{ 1.1, 4.4, 5.5, 3.3, 2.2, } fmt.Println(ls) //[1.1 4.4 5.5 3.3 2. ...

  4. 让Mac OS X专用高速移动硬盘在Linux下也能被读写

    MacBook Pro以及iMac等设备都具备雷电接口和USB 3.0接口,配合使用Mac OS X格式化的专用高速移动硬盘读写数据都非常快.那么这种硬盘可以在Linux下被读写吗?其实,Mac OS ...

  5. Delphi中Indy 10的安装和老版本的卸载

    http://www.cnblogs.com/railgunman/archive/2010/08/31/1814112.html Indy 10的安装和老版本的卸载 Indy 10下载地址: htt ...

  6. 通过quick2wire使用raspi的i2c和ks103通信

    原文:http://www.cnblogs.com/hangxin1940/archive/2013/04/04/2999015.html 之前介绍了如何启用i2c设备 http://www.cnbl ...

  7. ELK之Elasticsearch、logstash部署及配置

    ElasticSearch是一个搜索引擎,用来搜索.分析.存储日志; Logstash用来采集日志,把日志解析为json格式交给ElasticSearch; Kibana是一个数据可视化组件,把处理后 ...

  8. Servlet(生命周期)

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

  9. android EditText监听和长度监测事件

    <?xml version="1.0" encoding="utf-8"?> <!-- 定义基础的LinearLayout布局 --> ...

  10. BUPT 2012复试机考 4T

    题目描述 我们都学习过计算机网络,知道网络层IP协议数据包的头部格式如下: 其中IHL表示IP头的长度,单位是4字节:总长表示整个数据包的长度,单位是1字节.传输层的TCP协议数据段的头部格式如下:  ...