zoukankan      html  css  js  c++  java
  • Codeforces Round #352 (Div. 2) C

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

    题意:机器a坐标(ax,ay) 机器b坐标(bx,by) 垃圾桶坐标(tx,ty)    给你n个 垃圾的坐标

            机器每次只能把一个垃圾扔进垃圾桶(可以选择不移动) 问你将n个垃圾都扔进垃圾桶  机器a,b经过距离的总和的最小值

    题解:只需要判断最优的机器a,b的初始目标垃圾,分别按照s.dis*2-(s.dis+s.disa)=s.dis-s.disa (每个垃圾到垃圾桶的距离的二倍    -    机器a到垃圾的距离+垃圾到垃圾桶的距离)   s.dis*2-(s.dis+s.disb)=s.dis-s.disb(每个垃圾到垃圾桶的距离的二倍    -    机器b到垃圾的距离+垃圾到垃圾桶的距离) 排序

    取机器a,b最优的前两个可选初始点 a1 a2 b1 b2分三种情况

     1. a不动 b动 取b1

     2. a动 b不动  取a1

     3. a,b都动  (若a,b最优初始点相同,取a1 b2或者取b1 a2) 若不同 取a1 b1

     输出 三种情况的最小值;

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 #define ll __int64
     7 using namespace std;
     8 ll ax,ay,bx,by,tx,ty;
     9 ll n;
    10 double exm1,exm2,ans,ans1,ans2,ans3,anss;
    11 int biao1,biao2;
    12 double distance(ll aa,ll bb,ll cc,ll dd)
    13 {
    14     return sqrt((aa*1.0-cc*1.0)*(aa*1.0-cc*1.0)+(bb*1.0-dd*1.0)*(bb*1.0-dd*1.0));
    15 }
    16  double minx( double ss, double tt)
    17 {
    18     if(ss<tt)
    19      return ss;
    20      return tt;
    21 }
    22 struct node
    23 {
    24     int x,y;
    25     double dis;
    26     double disa;
    27     double disb;
    28     int flag;
    29 }N[100005],M[100005],a1,a2,b1,b2;
    30 bool cmp1(struct node s,struct node t)
    31 {
    32     if(s.dis+t.disa>t.dis+s.disa)
    33     return true;
    34     return false;
    35 }
    36 bool cmp2(struct node s,struct node t)
    37 {
    38     if(s.dis+t.disb>t.dis+s.disb)
    39     return true;
    40     return false;
    41 }
    42 int main()
    43 {
    44     scanf("%I64d %I64d %I64d %I64d %I64d %I64d",&ax,&ay,&bx,&by,&tx,&ty);
    45     scanf("%I64d",&n);
    46     ll xx,yy;
    47     for(ll i=1;i<=n;i++)
    48     {
    49         scanf("%I64d %I64d",&xx,&yy);
    50         N[i].x=xx;
    51         N[i].y=yy;
    52         N[i].dis=distance(xx,yy,tx,ty);
    53         N[i].disa=distance(xx,yy,ax,ay);
    54         N[i].disb=distance(xx,yy,bx,by);
    55         M[i].x=N[i].x;
    56         M[i].y=N[i].y;
    57         M[i].dis=N[i].dis;
    58         M[i].disa=N[i].disa;
    59         M[i].disb=N[i].disb;
    60         N[i].flag=i;
    61         M[i].flag=i;
    62     }
    63     ans1=0;
    64     for(ll i=1;i<=n;i++)
    65         ans1=ans1+N[i].dis*2.0;
    66     ans2=ans1;
    67     ans3=ans1;
    68     sort(N+1,N+n+1,cmp1);
    69     sort(M+1,M+n+1,cmp2);
    70     a1=N[1];a2=N[2];
    71     b1=M[1];b2=M[2];
    72     if(a1.x==b1.x&&a1.y==b1.y)
    73     {
    74        exm1=a1.dis-a1.disa+b2.dis-b2.disb;
    75        exm2=a2.dis-a2.disa+b1.dis-b1.disb;
    76        if(exm1>exm2)
    77            ans=exm1;
    78        else
    79            ans=exm2;
    80     }
    81     else
    82          ans=a1.dis-a1.disa+b1.dis-b1.disb;
    83     ans=ans1-ans;
    84     ans2=ans2-N[1].dis+N[1].disa;
    85     ans3=ans3-M[1].dis+M[1].disb;
    86     anss=minx(ans,ans2);
    87     anss=minx(anss,ans3);
    88     printf("%.12f
    ",anss);        
    89 }
  • 相关阅读:
    java 基础7
    java 基础5
    java 基础6
    java 基础4
    java 基础2
    java 基础3
    java 基础1
    使用HTML的基本结构创建网页
    jsp Servlet 文件上传
    Filter过滤器 不登陆无法访问其他页面
  • 原文地址:https://www.cnblogs.com/hsd-/p/5487633.html
Copyright © 2011-2022 走看看