感觉很简单,就是讨论一下
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef pair<double,int>pii;
const int N = 1e5+;
double x[N],y[N];
pii a[N],b[N];
double dis(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
double ax,ay,bx,by,tx,ty,sum=;
int n;
scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);
scanf("%d",&n);
for(int i=;i<=n;++i)
scanf("%lf%lf",&x[i],&y[i]);
for(int i=;i<=n;++i){
a[i].second=b[i].second=i;
double k1=dis(ax,ay,x[i],y[i]);
double k2=dis(bx,by,x[i],y[i]);
double k3=dis(tx,ty,x[i],y[i]);
sum+=k3*;
a[i].first=k1-k3;
b[i].first=k2-k3;
}
sort(a+,a++n);
sort(b+,b++n);
if(a[].first>=&&b[].first>=){
sum+=min(a[].first,b[].first);
}
else if(a[].first<&&b[].first>=){
sum+=a[].first;
}
else if(a[].first>=&&b[].first<){
sum+=b[].first;
}
else {
if(a[].second!=b[].second){
sum+=a[].first+b[].first;
}
else {
if(n==)sum+=min(a[].first,b[].first);
else {
double k1=a[].first+b[].first;
double k2=b[].first+a[].first;
k1=min(min(k1,k2),min(a[].first,b[].first));
sum+=k1;
}
}
}
printf("%.8f\n",sum);
return ;
}