C. Recycling Bottles
 

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
 
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,B,C三个点的坐标,C表示垃圾桶,A,B表示人

  在给你n个垃圾的坐标,问你两人每次最多可以携带一个垃圾到达垃圾桶

  将这n个垃圾全部扔进垃圾桶最少走多少路

  这里n个垃圾可以完全由其中一个或两个人捡起

题解:

  在人到达C后,我们知道之后这个人捡垃圾都是从C到垃圾距离*2

  我们假设所有垃圾都是从C出发捡的

  那么最优解就是从A,B出发所节省的,前提是至少有一个人出发了,按照节省多少进行排序

  找到节省最多的至多的两个点,更新答案

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+, M = 1e7, mod = 1e9+;
typedef long long ll; double dis( double a, double b, double x, double y) {
return (a-x)*(a-x)+(b-y)*(b-y);
} double X,Y,xx,yy,xh,yh,xxx,yyy;
int n;
double x[N],y[N];
struct ss{
double x,y,c,d;int ho,id;}p[N],P[N];
int cmp1(ss s1,ss s2) {
return s1.c<s2.c;
}
int main() {
cin>>X>>Y>>xx>>yy>>xh>>yh;
// scanf("%lf%lf%lf%lf%lf%lf",&X,&Y,&xx,&yy,&xh,&yh);
scanf("%d",&n);
double ans = 0.0;
int cnt = ;
for(int i=;i<=n;i++) {
cin>>xxx>>yyy;
if(xxx==xh&&yyy==yh) continue;
p[++cnt].x = xxx;
p[cnt].y = yyy;
// scanf("%lf%lf",&p[i].x,&p[i].y);
}
n = cnt;
for(int i=;i<=n;i++) {
ans = ans + sqrt(dis(xh,yh,p[i].x,p[i].y))*2.0;
}
double ans1 = 1e18;
for(int i=;i<=n;i++) {
p[i].c = sqrt(dis(X,Y,p[i].x,p[i].y)) - sqrt(dis(p[i].x,p[i].y,xh,yh));
p[i].id = i;
} for(int i=;i<=n;i++) {
P[i].id = p[i].id;
P[i].c = sqrt(dis(xx,yy,p[i].x,p[i].y)) - sqrt(dis(p[i].x,p[i].y,xh,yh)) ;
}
double t;
for(int i=;i<=n;i++) {
t = sqrt(dis(xx,yy,p[i].x,p[i].y));
ans1 = min(ans1,ans+t - sqrt(dis(p[i].x,p[i].y,xh,yh)));
t = sqrt(dis(X,Y,p[i].x,p[i].y));
ans1 = min(ans1,ans+t - sqrt(dis(p[i].x,p[i].y,xh,yh)));
}
sort(p+,p+n+,cmp1);
sort(P+,P+n+,cmp1);
for(int i=;i<=min(,n);i++) {
for(int j=;j<=min(,n);j++) {
if(p[i].id==P[j].id) continue;
double tmp1 = p[i].c;
double tmp2 = P[j].c;
ans1 = min(ans1,ans + tmp1 + tmp2);
}
}
printf("%.10f\n",ans1);
//cout << setprecision(10) << setiosflags(ios::scientific) << ans1 << endl;
return ;
}

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

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

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

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

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

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

  4. codeforces 352 div 2 C.Recycling Bottles 贪心

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

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

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

  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 Round #352 (Div. 2) C

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

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

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

随机推荐

  1. JavaScript 参数传递与变量复制

            ECMAScript 变量可能包含两种不同数据类型的值:基本类型值和引用类型值. 基本类型值指的是简单的数据段,而引用类型值指那些可能由多个值构成的对象.         5 种基本数 ...

  2. HDOJ 1907 John

    对于任意一个 Anti-SG 游戏,如果我们规定当局面中所有的单一游戏的 SG 值为 0 时,游戏结束,则先手必胜当且仅当:  (1)游戏的 SG 函数不为 0 且游戏中某个单一游戏的 SG 函数大于 ...

  3. PHP: Local 和 Global 作用域

    函数之外声明的变量拥有 Global 作用域,只能在函数以外进行访问. 函数内部声明的变量拥有 LOCAL 作用域,只能在函数内部进行访问. 下面的例子测试了带有局部和全局作用域的变量: 在上例中,有 ...

  4. 微信开发学习日记(八):7步看懂weiphp插件机制,核心目标是响应微信请求

    又经过了几个小时的梳理.回顾,截至目前,终于对weiphp这个框架的机制搞明白了些.想要完全明白,自然还需要大把的时间.第1步:   配置微信公众号,http://weiphp.jiutianniao ...

  5. lz4,pigz,gzip 3者比较

    一.压缩(1.1)使用gzip进行打包:# time tar -zcf tar1.tar binlog*real 0m48.497suser 0m38.371ssys 0m2.571s (1.2)使用 ...

  6. vim实用技巧

    <1> 删除空格: :% s/ //gi    #正则为一个空格,替换为空,全局匹配. <2> 删除空行: :g /^\n*$/ d  #g为global  正则为:行开始+换 ...

  7. django inclusion_tag

    一种比较普遍的tag类型是只是渲染其它模块显示下内容,这样的类型叫做Inclusion Tag. 例如,实现以下tag: {% books_for_author author %} 渲染结果为: &l ...

  8. petri网学习心得

    本文转载自duxw,如给您带来不便之处,请联系博主. 1.Petri网书籍:<petri网导论>,吴哲辉 非常适合初学者.概念清晰,容易理解. 2.工作流书籍:<Workflow M ...

  9. 简单方便地扩充Python的系统路径

    参考: http://www.elias.cn/Python/PythonPath?from=Develop.PythonPath http://v2in.com/pth-file-usage-in- ...

  10. 查看Eclipse中的jar包的源代码:jd-gui.exe

    前面搞了很久的使用JAD,各种下载插件,最后配置好了,还是不能用,不知道怎么回事, 想起一起用过的jd-gui.exe这个工具,是各种强大啊!!! 只需要把jar包直接扔进去就可以了,非常清晰,全部解 ...