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. jdbc学习笔记01

    回顾: day01-03,在上一篇文章文末 day04: 分组 group by 统计每个部门的平均工资: select deptno,avg(sal) from emp group by deptn ...

  2. selenium等待页面加载完成

    https://blog.csdn.net/hu_zhenghui/article/details/77429505 38行      这种方法 不准确   还在空白页时候   就会 返回  comp ...

  3. scrapy--dytt(电影天堂)

    喜欢看电影的小伙伴,如果想看新的电影,然后没去看电影院看,没有正确的获得好的方法,大家就可以在电影天堂里进行下载.这里给大家提供一种思路. 1.dytt.py # -*- coding: utf-8 ...

  4. SVN中Commit出现乱码的解决方案【转载】

    http://blog.csdn.net/thinkingcao/article/details/52797737 这几天在电脑上装了一个SVN,把Eclipse里面的工程全部Delete掉了,然后在 ...

  5. VIM 如何切换buffer

    命令 :ls 可查看当前已打开的buffer 命令 :b num 可切换buffer (num为buffer list中的编号) 其它命令: :bn -- buffer列表中下一个 buffer :b ...

  6. 减少Android staido 占用C 盘

    1.gradle 更换文件夹: 设置GRADLE_USER_HOME环境变量 在/etc/profile或~/.bash_profile增加如下: export GRADLE_USER_HOME=D: ...

  7. Java-JNA使用心得2

    自5月初第一次尝试使用Java封装调用C的dll之后,已经先后经历了3次小项目了. 上月末是最近的一次项目实际,任务来的急时间又少,还好在加班加点后还是完成了任务,并把第二次没有实现的功能给实现了(C ...

  8. FIFO页面淘汰算法

    1.优异虚拟存储系统,若进程在内存中占3页(开始时内存为空),若采用先进先出(FIFO)页面淘汰算法,当执行以下访问页号序列后1,3,4,2,1,3,5,1,2,5,4,2,会产生多少次缺页(9) 在 ...

  9. 从键盘输入数,输出它们的平方值&判断是不是2的阶次方数

    1.从键盘输入两个整数,然后输出它们的平方值和立方值 在Java中,没有像C语言那样有一个专供接受键盘输入值的scanf函数,所以一般的做法是从键盘输入一行字符,保存到字符串s中,再将字符组成的字符串 ...

  10. svn Previous operation has not finished; run 'cleanup' if it was interrupted

    svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted Usually, a ...