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 ≤ 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
  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.

题意:给你两个人,一个垃圾桶;利用人把垃圾全部进桶,使得距离最短;

思路:显然答案是sigma一个垃圾到垃圾桶距离的两倍;

    求出一个人动和两个人动的差值最大的距离;

    比较减去最大值;

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define mod 1000000007
  5. #define inf 999999999
  6. #define esp 0.00000000001
  7. //#pragma comment(linker, "/STACK:102400000,102400000")
  8. int scan()
  9. {
  10. int res = , ch ;
  11. while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
  12. {
  13. if( ch == EOF ) return << ;
  14. }
  15. res = ch - '' ;
  16. while( ( ch = getchar() ) >= '' && ch <= '' )
  17. res = res * + ( ch - '' ) ;
  18. return res ;
  19. }
  20. long double dis(long double a,long double b,long double c,long double d)
  21. {
  22. return sqrt((d-b)*(d-b)+(c-a)*(c-a));
  23. }
  24. struct is
  25. {
  26. long double cha;
  27. int pos;
  28. }a1[],b1[];
  29. int flag[];
  30. bool cmp(is x,is y)
  31. {
  32. return x.cha>y.cha;
  33. }
  34. int main()
  35. {
  36. long double a,b,c,d,e,f;
  37. cin>>a>>b>>c>>d>>e>>f;
  38. long double sum=;
  39. int x;
  40. scanf("%d",&x);
  41. for(int i=;i<x;i++)
  42. {
  43. long double u,v;
  44. cin>>u>>v;
  45. sum+=dis(e,f,u,v)*2.0;
  46. a1[i].cha=dis(e,f,u,v)-dis(u,v,a,b);
  47. b1[i].cha=dis(e,f,u,v)-dis(u,v,c,d);
  48. a1[i].pos=i;
  49. b1[i].pos=i;
  50. }
  51. if(x==)
  52. {
  53. //printf("%f\n",sum-max(a1[0].cha,b1[0].cha));
  54. cout << setprecision() << setiosflags(ios::scientific)<<sum-max(a1[].cha,b1[].cha)<<endl;
  55. return ;
  56. }
  57. sort(a1,a1+x,cmp);
  58. sort(b1,b1+x,cmp);
  59. double aa,bb;
  60. if(a1[].cha<&&b1[].cha<)
  61. {
  62. cout << setprecision() << setiosflags(ios::scientific)<<sum-max(a1[].cha,b1[].cha)<<endl;
  63. return ;
  64. }
  65. long double ans1;
  66. long double ans2;
  67. long double ans3;
  68. if(a1[].pos!=b1[].pos)
  69. ans3=a1[].cha+b1[].cha;
  70. else
  71. {
  72. if(a1[].cha+b1[].cha<a1[].cha+b1[].cha)
  73. ans3=a1[].cha+b1[].cha;
  74. else
  75. ans3=a1[].cha+b1[].cha;
  76. }
  77. ans2=a1[].cha;
  78. ans1=b1[].cha;
  79. cout << setprecision() << setiosflags(ios::scientific)<<sum-max(ans1,max(ans2,ans3))<<endl;
  80. return ;
  81. }

codeforces 352 div 2 C.Recycling Bottles 贪心的更多相关文章

  1. 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 ...

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

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

  3. 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 ...

  4. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  5. Codeforces 671A Recycling Bottles(贪心+思维)

    题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到 ...

  6. Codeforces Round #352 (Div. 2)

    模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...

  7. Codeforces Round #352 (Div. 2) (A-D)

    672A Summer Camp 题意: 1-n数字连成一个字符串, 给定n , 输出字符串的第n个字符.n 很小, 可以直接暴力. Code: #include <bits/stdc++.h& ...

  8. Codeforces Recycling Bottles 模拟

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

  9. codeforces 672C C. Recycling Bottles(计算几何)

    题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. POJ3096:Surprising Strings(map)

    http://poj.org/problem?id=3096 for循环真是奇妙! #include <string.h> #include <stdio.h> #includ ...

  2. [LeetCode] 628. Maximum Product of Three Numbers_Easy

    Given an integer array, find three numbers whose product is maximum and output the maximum product. ...

  3. AnsiString和各种数据类型间相互转换 [数据转换]

    //Ansistring 转 char void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString Test = " ...

  4. distinct count

    实验:查询一个column的无重复记录,需要知道有多少条记录,并显示记录. 统计记录用count(*)函数,无重复记录distinct,以emp表为例. (1)先查询无重复记录 [@more@] SQ ...

  5. kendo 级联加带搜索的下拉框以及js赋值

    1‘.js给下拉框赋值 $("#UserRole").data("kendoDropDownList").value(dataItem.RoleName); $ ...

  6. CMPXCHG指令

    一.CMPXCHG汇编指令详解. 这条指令将al\ax\eax\rax中的值与首操作数比较: 1.如果相等,第2操作数的直装载到首操作数,zf置1.(相当于相减为0,所以0标志位置位) 2.如果不等, ...

  7. Codeforces 1144G Two Merged Sequences

    题意: 将一个序列分成两个序列,两个序列中元素的相对顺序保持和原序列不变,使得分出的两个序列一个严格上升,一个严格下降. 思路: 我们考虑每个元素都要进入其中一个序列. 那么我们维护一个上升序列和一个 ...

  8. zw版【转发·台湾nvp系列Delphi例程】HALCON LocalMin2

    zw版[转发·台湾nvp系列Delphi例程]HALCON LocalMin2 procedure TForm1.Button1Click(Sender: TObject);var img : HUn ...

  9. Instruments(性能调优 12.3)

    Instruments Instruments是Xcode套件中没有被充分利用的一个工具.很多iOS开发者从没用过Instruments,或者只是用Leaks工具检测循环引用.实际上有很多Instru ...

  10. Linux服务器配置---ftp限制带宽

    限制带宽 ftp服务器可以设置每个用户的带宽,这样根据实际需求来分配,更加充分的利用系统资源.带宽通过参数“anon_max_rate“和”local_max_rate“来设置,这两个参数在配置文件中 ...