CodeForces 671A Recycling Bottles

时间:2022-03-30 21:26:30

暴力。

每个人找到一个入口,也就是从回收站到这个入口走的路程由人的位置到入口的路程来替代。

因此,只要找两个人分别从哪里入口就可以了。注意:有可能只要一个人走,另一人不走。

#pragma comment(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 namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
double ax,ay,bx,by,tx,ty;
struct X{ double x,y;int id; }s[maxn];
int n; bool cmp1(X a,X b)
{
return sqrt((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));
} bool cmp2(X a,X b)
{
return sqrt((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));
} bool cmp3(X a,X b)
{
return a.id<b.id;
} int a[maxn],sz; int main()
{
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",&s[i].x,&s[i].y),s[i].id=i; if(n==)
{
double ans;
ans=min(sqrt((ax-s[].x)*(ax-s[].x)+(ay-s[].y)*(ay-s[].y))+
sqrt((tx-s[].x)*(tx-s[].x)+(ty-s[].y)*(ty-s[].y))
,
sqrt((bx-s[].x)*(bx-s[].x)+(by-s[].y)*(by-s[].y))+
sqrt((tx-s[].x)*(tx-s[].x)+(ty-s[].y)*(ty-s[].y))
);
printf("%.6lf\n",ans);
return ;
} double ans=;
double g=;
for(int i=;i<=n;i++) g=g+*sqrt((s[i].x-tx)*(s[i].x-tx)+(s[i].y-ty)*(s[i].y-ty)); sort(s+,s++n,cmp1);
ans=min(ans,
g+sqrt((s[].x-ax)*(s[].x-ax)+(s[].y-ay)*(s[].y-ay))
-sqrt((s[].x-tx)*(s[].x-tx)+(s[].y-ty)*(s[].y-ty)));
for(int i=;i<=min(n,);i++) a[sz++]=s[i].id; sort(s+,s++n,cmp2);
ans=min(ans,
g+sqrt((s[].x-bx)*(s[].x-bx)+(s[].y-by)*(s[].y-by))
-sqrt((s[].x-tx)*(s[].x-tx)+(s[].y-ty)*(s[].y-ty)));
for(int i=;i<=min(n,);i++) a[sz++]=s[i].id; sort(s+,s++n,cmp3); for(int i=; i<sz; i++)
{
for(int j=; j<sz; j++)
{
if(a[j]==a[i]) continue; double tmp=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 ;
}