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. JQuery实现父级选择器(广告实现)

    效果图如下: HTML代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  2. django+xadmin在线教育平台(十)

    剩余app model注册 courses注册 新建courses/adminx.py: # encoding: utf-8 __author__ = 'mtianyan' __date__ = '2 ...

  3. 文件权限管理命令chmod,chown与文本搜索命令grep

    1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限. [root@bogon home]# cp -r /etc/sk ...

  4. Git版本控制使用方法入门教程

    1. 概述 对于软件版本管理工具,酷讯决定摒弃CVS而转向Git了. 为什么要选择Git? 你真正学会使用Git时, 你就会觉得这个问题的回答是非常自然的.然而当真正需要用文字来回答时,却觉得文字好像 ...

  5. Evevt Loop、任务队列、定时器等

    上周五,一个朋友发给我一道面试题,代码如下: console.log(1); setTimeout(console.log(2), 0); Promise.resolve().then(res =&g ...

  6. python Beautiful Soup库入门

    bs4库的HTML内容遍历方法 基于bs4库的HTML格式输出 显示:友好的显示 <tag>.prettify() 编码:bs4库将任何HTML输入都变成utf-8编码(python 3. ...

  7. DNS域名解析服务(bind)

    DNS(Domain Name System,域名系统): 用于管理和解析域名与IP地址对应关系的技术. 简单来说,就是能够接受用户输入的域名或IP地址,然后自动查找与之匹配(或者说具有映射关系)的I ...

  8. Java-JNA使用心得2

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

  9. centos使用--开机启动

    centos6.8 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd.mysqld.postfix等,安装后系统默认不会自动启 ...

  10. app分享功能开发

    最近在开发一个社交平台的app需要用到分享功能,本来想自己开发的,在网上花了很长时间查了很多教程结果却不尽人意,无意中看到还有类似的开源组件友推,结合自己的开发经验,把一些集成步骤和问题整理成文档奉献 ...