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. iOS多线程介绍

    一.线程概述 有些程序是一条直线,起点到终点:有些程序是一个圆,不断循环,直到将它切断.直线的如简单的Hello World,运行打印完,它的生命周期便结束了,像昙花一现那样:圆如操作系统,一直运行直 ...

  2. C++小思

    Bjarne那稀疏的棕褐色头发, 有点红的眼睛, 这个可爱的好老头, 感觉他更应该是一个哲学家, 因为他用编程的语言C++ 揭示了我们这个纷繁复杂世界的本质: 对象. 对的, 世界是由对象组成的, 并 ...

  3. Robberies

     Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  4. cocos基础教程(5)数据结构介绍之cocos2d::Value

    1.概述 cocos2d::Valie 是一个包含了很多原生类型(int,float,double,bool,unsigned char,char* 和 std::string)外加 std::vec ...

  5. zoj3745 Salary Increasing

    OJ Problem Set - 3745 Salary Increasing Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has ...

  6. 坚持不懈之linux haproxy 配置文件 详情

    ####################全局配置信息######################## #######参数是进程级的,通常和操作系统(OS)相关######### global maxc ...

  7. Ubuntu上如何安装Java,Eclipse,Pydev,Python(自带,不用装),BeautifulSoup

    如何安装Java,如果出于编程的需要安装Java,需要安装的是JDK,而不仅仅是JRE,下面说说如何在Ubuntu下如何安装JDK:只有两步,1.下载并解压,2.配置环境变量1.下载并解压:下载地址: ...

  8. MySQL性能优化的最佳经验

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  9. 【Linux】/dev/null 2>&1 详解

     今天一个朋友突然在自己的维护的Linux中, /var/spool/cron/root 中看到了以下的内容: 30 19 * * * /usr/bin/**dcon.sh > /dev/nul ...

  10. 56. 2种方法判断二叉树是不是平衡二叉树[is balanced tree]

    [本文链接] http://www.cnblogs.com/hellogiser/p/is-balanced-tree.html [题目] 输入一棵二叉树的根结点,判断该树是不是平衡二叉树.如果某二叉 ...