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. MySQL 高效分页

    create PROCEDURE USP_GetByPager( _pageindex int, _pagesize int ) BEGIN )*_pagesize; select * from A ...

  2. DetachedCriteria详细使用

    一.基本使用 1. 说明 Restrictions 是产生查询条件的工具类. 2. 定义 可以直接用class 创建 DetachedCriteria searDc = DetachedCriteri ...

  3. jquery json ajax

    当html中用script包含了不在同一个目录下的js外部文件(主要是为了通用代码的重用)时,这个js文件的 内容就如同在当前html文件中了,写jquery的时候不用考虑路径问题,可以直接引用htm ...

  4. 给setTimeout和setIntreval函数添加回调参数

    setTimeout和setInterval是两个很常见的计时函数.在以前,他们只接收两个参数,我们无法直接向他们的回调函数中添加参数,如果需要实现添加多个参数,可以在外层多嵌一层来实现类似的功能.现 ...

  5. POJ 3267 The Cow Lexicon

    又见面了,还是原来的配方,还是熟悉的DP....直接秒了... The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submis ...

  6. 习惯mac . OS X 安装MacPorts

    1. 安装必要的软件 安装MacPorts需要先安装X11和Xcode,Lion系统已经默认安装好了X11,在Appstore里安装Xcode即可. 下载完Xcode之后,一般路径在/Applicat ...

  7. php面试题之三——PHP语言基础(基础部分)

    三.PHP语言基础 1. strlen( )与 mb_strlen( )的作用分别是什么(新浪网技术部) strlen和mb_strlen都是用于获取字符串长度. strlen只针对单字节编码字符,也 ...

  8. 第19章 使用PXE+Kickstart部署无人值守安装

    章节概述: 本章节将教会您通过PXE+DHCP+TFTP+VSftpd+Kickstart服务程序搭建出无人值守安装系统,从而批量部署客户机系统. 这种系统能够实现自动化运维.避免了重复性劳动,帮助提 ...

  9. CoreLoation

    - (CLLocationManager *)locationManager { if (!_locationManager) { _locationManager = [[CLLocationMan ...

  10. CentOS6.5以runlevel 3开机时自动连接某无线设置示例

    [参考]http://blog.csdn.net/simeone18/article/details/8580592 [方法一] 假设无线网卡代号为wlan0,无线AP的essid为:TheWiFi, ...