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. WPF获取鼠标当前位置

    /// <summary> /// 设置鼠标的坐标 /// </summary> /// <param name="x">横坐标</par ...

  2. try catch finally执行顺序

    1.不管有木有出现异常,finally块中代码都会执行: 2.当try和catch中有return时,finally仍然会执行: 3.finally是在return表达式运算后前执行的,所以函数返回值 ...

  3. C++小思

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

  4. 怎样把excel一列分成多列

    1,选定要分列的列. 2,点击“数据”-“分列”. 3,在选项栏中设置如图 4,选择分隔符 4,看,分开了吧!

  5. 在Windows的Tomcat环境下部署Solr 4.7.0

    主要步骤如下: 1.下载solr-4.7.0.tgz; 2.解压缩solr-4.7.0.tgz,解压后目录结构如下: 3.将example/webapps目录下的solr.war复制到tomcat的w ...

  6. 繁华模拟赛 Evensgn玩序列

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  7. 微信和WeChat的合并月活跃账户数达到7.62亿了

    昨日,腾讯公布了截至2016年3月31日未经审核的第一季度综合业绩,其中财报显示微信和WeChat的合并月活跃账户数达到7.62亿,比去年同期增长39%.网络广告业务的收入同比增长73%至2016年第 ...

  8. Minimum Inversion Number

    Minimum Inversion Number Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  9. Intent的Flag

    小段代码: Intent it=new Intent(); it.setClass(Setting.this,Main.class);//从Setting跳转到Main it.addFlags(Int ...

  10. python学习之最简单的用户注册及登录验证小程序

    文章都是从我的个人博客上粘贴过来的哦,更多内容请点击 http://www.iwangzheng.com 正如很多同学所知道的,楼主开始学习python了,前进的道路曲曲折折,有荆棘也有陷阱,从最简单 ...