C. Recycling Bottles
time 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 ax, ay, bx, by, tx 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 .

Examples
Input
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: .

Bera will use the following path: .

Adil's path will be units long, while Bera's path will be units long.

题意:机器a坐标(ax,ay) 机器b坐标(bx,by) 垃圾桶坐标(tx,ty)    给你n个 垃圾的坐标

机器每次只能把一个垃圾扔进垃圾桶(可以选择不移动) 问你将n个垃圾都扔进垃圾桶  机器a,b经过距离的总和的最小值

题解:只需要判断最优的机器a,b的初始目标垃圾,分别按照s.dis*2-(s.dis+s.disa)=s.dis-s.disa (每个垃圾到垃圾桶的距离的二倍    -    机器a到垃圾的距离+垃圾到垃圾桶的距离)   s.dis*2-(s.dis+s.disb)=s.dis-s.disb(每个垃圾到垃圾桶的距离的二倍    -    机器b到垃圾的距离+垃圾到垃圾桶的距离) 排序

取机器a,b最优的前两个可选初始点 a1 a2 b1 b2分三种情况

1. a不动 b动 取b1

2. a动 b不动  取a1

3. a,b都动  (若a,b最优初始点相同,取a1 b2或者取b1 a2) 若不同 取a1 b1

输出 三种情况的最小值;

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll __int64
using namespace std;
ll ax,ay,bx,by,tx,ty;
ll n;
double exm1,exm2,ans,ans1,ans2,ans3,anss;
int biao1,biao2;
double distance(ll aa,ll bb,ll cc,ll dd)
{
return sqrt((aa*1.0-cc*1.0)*(aa*1.0-cc*1.0)+(bb*1.0-dd*1.0)*(bb*1.0-dd*1.0));
}
double minx( double ss, double tt)
{
if(ss<tt)
return ss;
return tt;
}
struct node
{
int x,y;
double dis;
double disa;
double disb;
int flag;
}N[],M[],a1,a2,b1,b2;
bool cmp1(struct node s,struct node t)
{
if(s.dis+t.disa>t.dis+s.disa)
return true;
return false;
}
bool cmp2(struct node s,struct node t)
{
if(s.dis+t.disb>t.dis+s.disb)
return true;
return false;
}
int main()
{
scanf("%I64d %I64d %I64d %I64d %I64d %I64d",&ax,&ay,&bx,&by,&tx,&ty);
scanf("%I64d",&n);
ll xx,yy;
for(ll i=;i<=n;i++)
{
scanf("%I64d %I64d",&xx,&yy);
N[i].x=xx;
N[i].y=yy;
N[i].dis=distance(xx,yy,tx,ty);
N[i].disa=distance(xx,yy,ax,ay);
N[i].disb=distance(xx,yy,bx,by);
M[i].x=N[i].x;
M[i].y=N[i].y;
M[i].dis=N[i].dis;
M[i].disa=N[i].disa;
M[i].disb=N[i].disb;
N[i].flag=i;
M[i].flag=i;
}
ans1=;
for(ll i=;i<=n;i++)
ans1=ans1+N[i].dis*2.0;
ans2=ans1;
ans3=ans1;
sort(N+,N+n+,cmp1);
sort(M+,M+n+,cmp2);
a1=N[];a2=N[];
b1=M[];b2=M[];
if(a1.x==b1.x&&a1.y==b1.y)
{
exm1=a1.dis-a1.disa+b2.dis-b2.disb;
exm2=a2.dis-a2.disa+b1.dis-b1.disb;
if(exm1>exm2)
ans=exm1;
else
ans=exm2;
}
else
ans=a1.dis-a1.disa+b1.dis-b1.disb;
ans=ans1-ans;
ans2=ans2-N[].dis+N[].disa;
ans3=ans3-M[].dis+M[].disb;
anss=minx(ans,ans2);
anss=minx(anss,ans3);
printf("%.12f\n",anss);
}

Codeforces Round #352 (Div. 2) C的更多相关文章

  1. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  2. Codeforces Round #352 (Div. 2) D. Robin Hood

    题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...

  3. Codeforces Round #352 (Div. 2) D. Robin Hood (二分答案)

    题目链接:http://codeforces.com/contest/672/problem/D 有n个人,k个操作,每个人有a[i]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差 ...

  4. Codeforces Round #352 (Div. 1) B. Robin Hood 二分

    B. Robin Hood 题目连接: http://www.codeforces.com/contest/671/problem/B Description We all know the impr ...

  5. Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力

    A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...

  6. Codeforces Round #352 (Div. 2) B. Different is Good 水题

    B. Different is Good 题目连接: http://www.codeforces.com/contest/672/problem/B Description A wise man to ...

  7. Codeforces Round #352 (Div. 2) A. Summer Camp 水题

    A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...

  8. Codeforces Round #352 (Div. 2) ABCD

    Problems     # Name     A Summer Camp standard input/output 1 s, 256 MB    x3197 B Different is Good ...

  9. Codeforces Round #352 (Div. 2)

    模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...

  10. Codeforces Round #352 (Div. 2) B - Different is Good

    A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to b ...

随机推荐

  1. 6-1 md5加密

    1.导入hashlib模块,使用它的md5方法进行加密 import hashlib # import md5 python2 s = 'admin123' # .将字符串类型转换成byte类型才能加 ...

  2. ethereum(以太坊)(十二)--应用(二)__投票(基础总和)

    编写应用合约之前,先弄清它的逻辑,有助于我们更好的部署合约 pragma solidity ^0.4.21; pragma experimental ABIEncoderV2; contract vo ...

  3. js如何获得系统时间年月日时分秒

    javascript 自带有个对象(构造函数),Date().下面是代码: 回答一: var now = new Date();  var nowTime = now.toLocaleString() ...

  4. POJ:2739-Sum of Consecutive Prime Numbers(尺取)

    Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27853 Ac ...

  5. python正则表达式01--贪心算法和非贪心算法findall()

    import re st = 'asdfasxxixxdafqewxxlovexxsadawexxyouxxas' # . #点匹配除换行符外的任意字符 a0 = re.findall('xx.',s ...

  6. Storm: 集群安装和配置

    前期准备:3台服务器: 192.168.8.94  192.168.8.95 192.168.8.96 去storm官网下载响应版本的软件包:http://storm.apache.org/downl ...

  7. 4 . GET方法实现文章分类

    复习:博客站点 <!DOCTYPE html> {% load staticfiles %} <html> <head> <meta charset=&quo ...

  8. Android toolbar menu 字体点击样式

    今天在做toolbar的时候,右边的菜单的点击事件,就是文字,然后文字的样式,文字的大小,文字的颜色,高了半天.最后发现,文字点下去之后是有样式的,也就是按下去有阴影. 哥哥的耐心好,就知道这不是问题 ...

  9. ACE_DEBUG buffer

    ACE中输出日志时,发现太长会被截断. 1.测试 ] = {}; ACE_OS::memset(buf,); ACE_DEBUG((LM_INFO, ACE_TEXT("##@@##[ %s ...

  10. Python基础——安装运行

    Python是如何运行的? 像绝大多数编程语言一样,要在计算机上能够运行python程序,至少需要安装一个最小的Python包:一个Python解释器和支持的库. 安装Python 安装包下载:htt ...