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 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 .

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.

题意:给你两个人,一个垃圾桶;利用人把垃圾全部进桶,使得距离最短;

思路:显然答案是sigma一个垃圾到垃圾桶距离的两倍;

    求出一个人动和两个人动的差值最大的距离;

    比较减去最大值;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define esp 0.00000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
long double dis(long double a,long double b,long double c,long double d)
{
return sqrt((d-b)*(d-b)+(c-a)*(c-a));
}
struct is
{
long double cha;
int pos;
}a1[],b1[];
int flag[];
bool cmp(is x,is y)
{
return x.cha>y.cha;
}
int main()
{
long double a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
long double sum=;
int x;
scanf("%d",&x);
for(int i=;i<x;i++)
{
long double u,v;
cin>>u>>v;
sum+=dis(e,f,u,v)*2.0;
a1[i].cha=dis(e,f,u,v)-dis(u,v,a,b);
b1[i].cha=dis(e,f,u,v)-dis(u,v,c,d);
a1[i].pos=i;
b1[i].pos=i;
}
if(x==)
{
//printf("%f\n",sum-max(a1[0].cha,b1[0].cha));
cout << setprecision() << setiosflags(ios::scientific)<<sum-max(a1[].cha,b1[].cha)<<endl;
return ;
}
sort(a1,a1+x,cmp);
sort(b1,b1+x,cmp);
double aa,bb;
if(a1[].cha<&&b1[].cha<)
{
cout << setprecision() << setiosflags(ios::scientific)<<sum-max(a1[].cha,b1[].cha)<<endl;
return ;
}
long double ans1;
long double ans2;
long double ans3;
if(a1[].pos!=b1[].pos)
ans3=a1[].cha+b1[].cha;
else
{
if(a1[].cha+b1[].cha<a1[].cha+b1[].cha)
ans3=a1[].cha+b1[].cha;
else
ans3=a1[].cha+b1[].cha;
}
ans2=a1[].cha;
ans1=b1[].cha;
cout << setprecision() << setiosflags(ios::scientific)<<sum-max(ans1,max(ans2,ans3))<<endl;
return ;
}

codeforces 352 div 2 C.Recycling Bottles 贪心的更多相关文章

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

    C. Recycling Bottles   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Centr ...

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

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

  3. Codeforces Round #352 (Div. 2) C. Recycling Bottles

      C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

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

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

  5. Codeforces 671A Recycling Bottles(贪心+思维)

    题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到 ...

  6. Codeforces Round #352 (Div. 2)

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

  7. Codeforces Round #352 (Div. 2) (A-D)

    672A Summer Camp 题意: 1-n数字连成一个字符串, 给定n , 输出字符串的第n个字符.n 很小, 可以直接暴力. Code: #include <bits/stdc++.h& ...

  8. Codeforces Recycling Bottles 模拟

    C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...

  9. codeforces 672C C. Recycling Bottles(计算几何)

    题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. Kylin安装部署

    一.安装准备 1.操作系统 Centos 7.x 2.时间问题 集群内所有节点时间一定要同步. NTP.Chrony 3.用户 创建hadoop组和hadoop用户,并做ssh免密码登录 4.Hado ...

  2. matplotlib —— 调整坐标轴

    import matplotlib.pyplot as plt import numpy as np # 绘制普通图像 x = np.linspace(-1, 1, 50) y1 = 2 * x + ...

  3. javascript函数定义以及常见用法

                  我们知道,js函数有多种写法,函数声明 ,函数表达式,Function式构造函数,自执行函数,包括Es6的箭头函数,Class类写法,高阶函数,函数节流/函数防抖,下面我就 ...

  4. yii2csrf攻击

    第一种解决办法是关闭Csrf public function init(){ $this->enableCsrfValidation = false; } 第二种解决办法是在form表单中加入隐 ...

  5. python+Django框架运用(三)

    Django模型 模式指的是根据数据库中数据表的结构来创建出来的class,每一张表到Python中就是一个 class,表中的每一个列,到Python中就是class的一个属性. 在模型中可以完成对 ...

  6. ORTP编译为静态库的问题

    项目中需要用到ORTP,我采用的编译环境是 VC2013,当我在项目设置中将设置为静态库是,发现没有导出函数,比如在需要连接 oRTP.lib库时提示 找不到 ORTP_init; 解决办法是 :在O ...

  7. linux查看是否有某个运行的进程命令

    linux查看是否有某个运行的进程命令:例如,查询是否包含 “my_post” 关键字的进程 ps aux | grep my_post ps aux | grep  my_post | grep - ...

  8. 文件和打印机共享 win7 and xp

    Win7 摘自:https://www.xp510.com/article/4249.html 首先开启服务 方法:开始---所有程序---附件---运行---输入services.msc----确定 ...

  9. P3008 [USACO11JAN]道路和飞机Roads and Planes

    P3008 [USACO11JAN]道路和飞机Roads and Planes Dijkstra+Tarjan 因为题目有特殊限制所以不用担心负权的问题 但是朴素的Dijkstra就算用堆优化,也显然 ...

  10. Linux 安装JDK(jdk-8u121-linux-x64.tar.gz)

    Linux 安装JDK(jdk-8u121-linux-x64.tar.gz) 一.JDK准备 1.1 文件名称 jdk-8u121-linux-x64.tar.gz 1.2 下载地址 http:// ...