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. cocos基础教程(1)Mac环境下搭建

    下面主要介绍cocos2d-x环境的设置以及android的环境搭建 1.下载cocos2d-x 3.0正式版      http://www.cocos2d-x.org/download 2.下载a ...

  2. MVC中的_viewstart.cshtml(没有设置Layout却引用了布局)

    今天Home视图中新增了一个视图,因为不需要设置Layout就没与管他,但是运行起来一看,自动引用了布局,分析了半天 也没看出是哪的错误? 后来尝试着在area中增加了一个同样的视图就没有问题,比较这 ...

  3. java笔记--关于int和byte[]的转换

    关于int和byte[]数组的转换 --如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3891747.html "谢谢-- 众所 ...

  4. [Effective JavaScript 笔记]第24条:使用变量保存arguments对象

    迭代器(iterator)是一个可以顺序存取数据集合的对象.其一个典型的API是next方法.该方法获得序列中的下一个值. 迭代器示例 题目:希望编写一个便利的函数,它可以接收任意数量的参数,并为这些 ...

  5. C语言可以包含.txt文件

    // fa.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include "iostream"#include" ...

  6. Linux 日志文件utmp、wtmp、lastlog、messages

            1.有关当前登录用户的信息记录在文件utmp中:==who命令 2.登录进入和退出纪录在文件wtmp中:==w命令 3.最后一次登录文件可以用lastlog命令察看: 4.messag ...

  7. ubuntu12 apache2部署多个网站的方法

    由于对apache2的配置不是很精通.吃了不少瘪. 这里总结下,希望对碰到同样问题的人带来帮助: 假设需求是有两个站点,site1和site2.其端口分别为80和8080. 1. 配置监听端口 修改 ...

  8. java面试总结-(hibernate ibatis struts2 spring)

    说说Hibernate对象的三种状态 Hibernate对象有三种状态,分别是:临时态(Transient). 持久态(Persistent).游离态(Detached). 临时状态:是指从对象通过n ...

  9. Python OpenSource Project

    http://www.oschina.net/project/lang/25/python

  10. ajax:post 400错误

    POST http://localhost:8080/purchase/purchase-apply/update.htm 400 (Bad Request) n.ajaxTransport.k.co ...