首页 技术 正文
技术 2022年11月14日
0 收藏 676 点赞 3,132 浏览 3874 个字

 C. Recycling Bottlestime limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

It was 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 recycling bin.

We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). 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 was 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 are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it’s allowed that one of them stays still while the other one continues to pick bottles.

They want to organize the process such that 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 integers axaybxbytx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.

The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.

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

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

Output

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

Namely: let’s assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if Codeforces Round #352 (Div. 2) C. Recycling Bottles.

Examplesinput

3 1 1 2 0 0
3
1 1
2 1
2 3

output

11.084259940083

input

5 0 4 2 2 0
5
5 2
3 0
5 5
3 5
3 3

output

33.121375178000

Note

Consider the first sample.

Adil will use the following path: Codeforces Round #352 (Div. 2) C. Recycling Bottles.

Bera will use the following path: Codeforces Round #352 (Div. 2) C. Recycling Bottles.

Adil’s path will be Codeforces Round #352 (Div. 2) C. Recycling Bottles units long, while Bera’s path will be Codeforces Round #352 (Div. 2) C. Recycling Bottles units long.

题目大意:平面上有n个垃圾,每个垃圾有个坐标,现在A 和B想把垃圾放到垃圾箱内,A或B至少有一个人得捡垃圾这样才能把所有垃圾捡完。

解题思路:分析我们可以发现,当a或b走到垃圾桶后,后面所用的时间是不变的,即 Σ垃圾桶到垃圾的距离的2倍。

暴力。为了写代码方便,先处理出垃圾到a的距离disa[i] 垃圾到b的距离disb[i]  垃圾到垃圾桶的距离dis[i]。

暴力3种情况。(1)只有A在捡垃圾 (2)只有B在捡垃圾

(3)A,B都捡垃圾.。  ans=sum+min(dis[id1]-disa[id1])+min(dis[id2]-disb[id2] )  (id1!=id2)。      

/* ***********************************************
Author :guanjun
Created Time :2016/5/12 19:34:55
File Name :cf352c.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100100
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;double dist(double a,double b,double c,double d){
return sqrt((a-c)*(a-c)+(b-d)*(b-d));
}
double disa[maxn];
double disb[maxn];
double dis[maxn];
double disk[maxn];
double Min1,Min2,ans;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
double a,b,c,d,e,f;
int n;
double x,y;
while(cin>>a>>b>>c>>d>>e>>f>>n){
double sum=;
for(int i=;i<=n;i++){
scanf("%lf %lf",&x,&y);
disa[i]=dist(a,b,x,y);
disb[i]=dist(c,d,x,y);
dis[i]=dist(e,f,x,y);
sum+=dis[i];
}
sum*=2.0;
Min1=Min2=1e19;
for(int i=;i<=n;i++){
Min1=min(Min1,disa[i]-dis[i]);
Min2=min(Min2,disb[i]-dis[i]);
}
ans=min(sum+Min1,sum+Min2);//当有一个不动的时候
int id1=-,id2=-;
Min1=Min2=1e19;
for(int i=;i<=n;i++){
if(disb[i]-dis[i]<Min1){
Min1=disb[i]-dis[i];
id1=i;
}
}
for(int i=;i<=n;i++){
if(disa[i]-dis[i]<Min2&&(id1!=i)){
Min2=disa[i]-dis[i];
id2=i;
}
}
ans=min(ans,sum+Min1+Min2);
Min1=Min2=1e19;
for(int i=;i<=n;i++){
if(disa[i]-dis[i]<Min1){
Min1=disa[i]-dis[i];
id1=i;
}
}
for(int i=;i<=n;i++){
if(disb[i]-dis[i]<Min2&&(id1!=i)){
Min2=disb[i]-dis[i];
id2=i;
}
}
ans=min(ans,sum+Min1+Min2);
printf("%.10f\n",ans);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,117
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,590
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927