#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-6;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} Template<classT>inlinevoidRead (T &x) { CharC=getchar (); x=0; while(!isdigit (c)) c=GetChar (); while(IsDigit (c)) {x=x*Ten+c-'0'; C=GetChar ();}}Const intmaxn=100010;DoubleAx,ay,bx,by,tx,ty;structx{Doublex, y;intID;} S[MAXN];intN;BOOLCmp1 (X a,x b) {returnsqrt ((a.x-ax) * (A.x-ax) + (a.y-ay) * (A.y-ay))-sqrt ((A.X-TX) * (A.X-TX) + (a.y-ty) * (a.y-ty)) <sqrt ((b.x-AX) * (B.x-ax) + (b.y-ay) * (B.y-ay))-sqrt ((B.X-TX) * (B.X-TX) + (b.y-ty) * (b.y-ty));}BOOLCMP2 (X a,x b) {returnsqrt ((A.X-BX) * (A.X-BX) + (a.y-by) * (a.y-by))-sqrt ((A.X-TX) * (A.X-TX) + (a.y-ty) * (a.y-ty)) <sqrt ((b.x-BX) * (B.X-BX) + (b.y-by) * (b.y-by))-sqrt ((B.X-TX) * (B.X-TX) + (b.y-ty) * (b.y-ty));}BOOLCmp3 (X a,x b) {returna.id<b.id;}intA[maxn],sz;intMain () {scanf ("%LF%LF%LF%LF%LF%LF",&ax,&ay,&bx,&by,&tx,&ty); scanf ("%d",&N); for(intI=1; i<=n;i++) scanf ("%LF%LF", &s[i].x,&s[i].y), s[i].id=i; if(n==1) { Doubleans; Ans=min (sqrt (ax-s[1].x) * (ax-s[1].x) + (ay-s[1].Y) * (ay-s[1].Y)) +sqrt (TX-s[1].x) * (tx-s[1].x) + (ty-s[1].Y) * (ty-s[1].y)), sqrt (BX-s[1].x) * (bx-s[1].x) + (by-s[1].Y) * (by-s[1].Y)) +sqrt (TX-s[1].x) * (tx-s[1].x) + (ty-s[1].Y) * (ty-s[1( ].y))); printf ("%.6lf\n", ans); return 0; } Doubleans=999999999999999999; Doubleg=0; for(intI=1; i<=n;i++) g=g+2*sqrt ((S[I].X-TX) * (S[I].X-TX) + (s[i].y-ty) * (s[i].y-ty)); Sort (S+1, s+1+N,CMP1); Ans=min (ans, g+sqrt ((s[1].X-AX) * (s[1].x-ax) + (s[1].y-ay) * (s[1].y-ay)) -sqrt ((s[1].X-TX) * (s[1].X-TX) + (s[1].y-ty) * (s[1].y-ty)); for(intI=1; I<=min (N,2); i++) a[sz++]=s[i].id; Sort (S+1, s+1+N,CMP2); Ans=min (ans, g+sqrt ((s[1].X-BX) * (s[1].X-BX) + (s[1].y-by) * (s[1].y-by )) -sqrt ((s[1].X-TX) * (s[1].X-TX) + (s[1].y-ty) * (s[1].y-ty)); for(intI=1; I<=min (N,2); i++) a[sz++]=s[i].id; Sort (S+1, s+1+N,cmp3); for(intI=0; i<sz; i++) { for(intj=0; j<sz; J + +) { if(A[j]==a[i])Continue; Doubletmp=G; TMP=tmp+sqrt ((s[a[i]].x-ax) * (S[a[i]].x-ax) + (s[a[i]].y-ay) * (s[a[i]].y-ay)); TMP=tmp+sqrt ((S[A[J]].X-BX) * (S[A[J]].X-BX) + (s[a[j]].y-by) * (s[a[j]].y-by )); TMP=tmp-sqrt ((S[A[I]].X-TX) * (S[A[I]].X-TX) + (s[a[i]].y-ty) * (s[a[i]].y-ty)); TMP=tmp-sqrt ((S[A[J]].X-TX) * (S[A[J]].X-TX) + (s[a[j]].y-ty) * (s[a[j]].y-ty)); Ans=min (ans,tmp); }} printf ("%.6lf\n", ans); return 0;}
Codeforces 671A Recycling Bottles