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

Source: Internet
Author: User

C. Recycling bottles

It is 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 recycli Ng bin.

We can think central Perk as coordinate plane. There was n bottles on the ground, the i-th bottle was located at position (x i, y i). 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 is 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 is allowed to pick bottles simultaneously, all bottles is picked by any of the, it's allowed that one of the M stays still while the other one continues to pick bottles.

They want to organize the process such, 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 integersa x ,   a y ,   b x b y ,   t Span class= "Lower-index" > x  and  t y   (0≤ a x , a y , b x , b y , t x , t y ≤10< Span class= "Upper-index" >9)  -initial positions of Adil, Bera and recycling bin respectively.

The second line contains a single integer n (1≤ n ≤100)-the number of bottles on the Gro und.

Then follow n lines, each of them contains II integers xi and y i ( 0≤ xi, yi ≤109)-position of the i-th bottle.

It's guaranteed that positions of Adil, Bera, recycling bin and all bottles is distinct.

Output

Print one real number-the minimum possible total distance Adil and Bera need to walk in order to put all bottles into re Cycling bin. Your answer would be considered correct if it absolute or relative error does not exceed 6.

Namely:let ' s assume that your answer are a, and the answer of the jury is b. The checker program would consider your answer correct if.

Examplesinput
3 1 1 2 0 0
3
1 1
2 1
2 3
Output
11.084259940083
Note

Consider the first sample.

Adil'll use the following path:.

Bera'll use the following path:.

Adil's path would be units long and while Bera's path would be units long.

Test instructions

I'll give you the coordinates of the a,b,c three points, c means the Trash, A, b indicates the person

To give you the coordinates of the garbage, ask you two people can carry a maximum of one garbage to the garbage bin at a time

Throw all these n rubbish in the trash, at least how many roads.

Here n rubbish can be picked up entirely by one or two of them

Exercises

After the person arrives at C, we know that after this person pick up rubbish from c to trash distance

We assume all the rubbish was picked up from c.

Then the optimal solution is saved from A, B, provided that at least one person starts, according to the number of savings to be sorted

Find the most saved up to two points and update the answer

#include <bits/stdc++.h>using namespacestd;Const intN = 1e6+ -, M = 1e7, mod = 1e9+7; typedefLong Longll;DoubleDisDoubleADoubleBDoubleXDoubley) {return(a-x) * (a-x) + (b-y) * (b-y);} Doublex,y,xx,yy,xh,yh,xxx,yyy;intN;DoubleX[n],y[n];structss{DoubleX,y,c,d;intHo,id;} P[n],p[n];intCMP1 (ss S1,ss S2) {returns1.c<s2.c;}intMain () {CIN>>X>>Y>>xx>>yy>>xh>>YH; //scanf ("%lf%lf%lf%lf%lf%lf", &x,&y,&xx,&yy,&xh,&yh);scanf"%d",&N); DoubleAns =0.0; intCNT =0;  for(intI=1; i<=n;i++) {cin>>xxx>>yyy; if(XXX==XH&AMP;&AMP;YYY==YH)Continue; p[++cnt].x =xxx; P[cnt].y=yyy; //scanf ("%lf%lf", &p[i].x,&p[i].y);} n=CNT;  for(intI=1; i<=n;i++) {ans= ans + sqrt (dis (xh,yh,p[i].x,p[i].y)) *2.0; }     DoubleANS1 =1e18;  for(intI=1; i<=n;i++) {p[i].c= sqrt (DIS (x,y,p[i].x,p[i].y))-sqrt (DIS (p[i].x,p[i].y,xh,yh)); P[i].id=i; }     for(intI=1; i<=n;i++) {p[i].id=p[i].id; P[I].C= sqrt (DIS (xx,yy,p[i].x,p[i].y))-sqrt (DIS (p[i].x,p[i].y,xh,yh)); }     DoubleT;  for(intI=1; i<=n;i++) {T=sqrt (DIS (xx,yy,p[i].x,p[i].y)); Ans1= Min (Ans1,ans+t-sqrt (DIS (P[I].X,P[I].Y,XH,YH))); T=sqrt (DIS (x,y,p[i].x,p[i].y)); Ans1= Min (Ans1,ans+t-sqrt (DIS (P[I].X,P[I].Y,XH,YH))); } sort (P+1, p+n+1, CMP1); Sort (P+1, p+n+1, CMP1);  for(intI=1; I<=min ( -, n); i++) {         for(intj=1; J<=min ( -, n); j + +) {            if(p[i].id==p[j].id)Continue; DoubleTMP1 =p[i].c; DoubleTMP2 =p[j].c; Ans1= min (Ans1,ans + TMP1 +TMP2); }} printf ("%.10f\n", ans1); //cout << setprecision (Ten) << setiosflags (ios::scientific) << ans1 << Endl;    return 0;}

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.