Idea: After analyzing this problem, we will find that when two people pick up the first bottle, the minimum value of the road after the walk will not change. So just find out two cases where the first bottle is the minimum value (one of them does not go, one goes). If there are two or one person to the first bottle of the weight value is greater than the bottle to the recovery point, choose the one with the right value.
And when calculating the minimum value, simply take out the minimum of two weights in the array of the smallest two numbers can not be selected all over the history.
#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>using namespacestd;Doublea[100100],b[100100],t[100100];Doubleminn[4],sum,chang;intunder[4];DoubleDistanceDoubleXDoubleYDoubleX1,Doubley1) { returnsqrt (POW (x-x1) *1.0,2) +pow ((y-y1) *1.0,2)+0.0);}intMain () {//int ax,ay,bx,by,tx,ty,n,tempx,tempy; intN; DoubleAx,ay,bx,by,tx,ty,tempx,tempy; scanf ("%LF%LF%LF%LF%LF%LF",&ax,&ay,&bx,&by,&tx,&ty); scanf ("%d",&N); Sum=0; for(intI=1; i<=n;i++) {scanf ("%LF%LF",&tempx,&tempy); T[i]=distance (tx,ty,tempx,tempy); Sum+=2*T[i]; A[i]= Distance (ax,ay,tempx,tempy)-T[i]; B[i]= Distance (bx,by,tempx,tempy)-T[i]; //cout<<a[i]<< "" <<b[i]<<endl;} minn[0] = a[1];under[0] =1; minn[2] = b[1];under[2] =1; //find the two minimum values of the A[i] array for(intI=1; i<=n;i++){ if(a[i]<minn[0]) {minn[0] =A[i]; under[0] =i; } } for(intI=1; i<=n;i++)if(i!=under[0]) minn[1] = a[i],under[1] =i; for(intI=1; i<=n;i++){ if(i!=under[0]&&a[i]<minn[1]) {minn[1] =A[i]; under[1] =i; } } //find the two minimum values of the B[i] array for(intI=1; i<=n;i++){ if(b[i]<minn[2]) {minn[2] =B[i]; under[2] =i; } } for(intI=1; i<=n;i++)if(i!=under[2]) minn[3] = b[i],under[3] =i; for(intI=1; i<=n;i++){ if(i!=under[2]&&b[i]<minn[3]) {minn[3] =B[i]; under[3] =i; } } //when the n=1, there will be no two minimum value, so as a special case? if(n==1) Chang = min (a[1],b[1]); Else if(under[0]!=under[2]) {Chang= Min (min (minn[0]+minn[2],minn[0]), minn[2]); }Else{Chang= Min (min (min (minn[0]+minn[3],minn[1]+minn[2]), minn[0]), minn[2]); } printf ("%.12lf\n", sum+Chang); return 0;}
Codeforces Round #352 (Div. 2) C. Recycling Bottles (enumeration)