C. Recycling Bottles
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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
input
5 0 4 2 2 0
5
5 2
3 0
5 5
3 5
3 3
output
33.121375178000
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.


稍微一想,除了开始后面都是从bin来回

只要找从a b到某个瓶子比从bin到节省最多就可以了

特殊情况太多:

有人是负值 不走他

最优瓶子一样 找次优

次优中还有负值

调了一个多小时,WA无数

//
// main.cpp
// cf672c
//
// Created by Candy on 9/15/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const double INF=1e10;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int xa,ya,xb,yb,xt,yt,x,y;
int n,bot[];
double mx[],sum=;//1 2->a 3 4->b
double dist(ll a,ll b){
return sqrt(a*a+b*b);
}
double getans(double a,double b){
if(a<||b<){//printf("flag2\n");
if(a<b) a=;
else b=;
}
return a+b;
}
int main(int argc, const char * argv[]) {
mx[]=mx[]=mx[]=mx[]=-INF;
scanf("%d%d%d%d%d%d%d",&xa,&ya,&xb,&yb,&xt,&yt,&n);//cout<<"\na"<<xa<<" "<<ya<<"\n";
for(int i=;i<=n;i++){
x=read();y=read();
double to=dist(x-xt,y-yt); sum+=to*;//printf("to %d %d %lf\n",x-xt,y-yt,to);
double t1=to-dist(x-xa,y-ya),t2=to-dist(x-xb,y-yb);
if(t1>mx[]){
mx[]=mx[]; bot[]=bot[];
mx[]=t1; bot[]=i;
}else if(t1>mx[]){
mx[]=t1; bot[]=i;
}
if(t2>mx[]){
mx[]=mx[]; bot[]=bot[];
mx[]=t2; bot[]=i;
}else if(t2>mx[]){
mx[]=t2; bot[]=i;
}
} //if(n==1) {printf("%.12f",sum-max(mx[1],mx[3]));return 0;}
//printf("%lf %d %lf %d\n",mx[1],bot[1],mx[3],bot[3]);
if(mx[]<||mx[]<){//printf("flag2\n");
if(mx[]<mx[]) mx[]=,bot[]=;
else mx[]=,bot[]=;
}
if(bot[]==bot[]){//printf("flag1 %lf %lf\n",mx[2],mx[4]);
if(getans(mx[],mx[])>getans(mx[],mx[])){
mx[]=mx[];//cout<<mx[1]<<" mx1\n";
}else{
mx[]=mx[];//,cout<<mx[3]<<" mx3\n";
}
if(mx[]<||mx[]<){//printf("flag2\n");
if(mx[]<mx[]) mx[]=,bot[]=;
else mx[]=,bot[]=;
}
}
printf("%.12f",sum-mx[]-mx[]);
return ;
}

CF 672C Recycling Bottles[最优次优 贪心]的更多相关文章

  1. codeforces 672C - Recycling Bottles 贪心水题

    感觉很简单,就是讨论一下 #include <stdio.h> #include <string.h> #include <algorithm> #include ...

  2. codeforces 672C C. Recycling Bottles(计算几何)

    题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input s ...

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

    C. Recycling Bottles   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Centr ...

  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. CF 672C 两个人捡瓶子 最短路与次短路思想

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

  6. CF 628C --- Bear and String Distance --- 简单贪心

    CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...

  7. Codeforces Recycling Bottles 模拟

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

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

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

  9. Codeforces 671 A——Recycling Bottles——————【思维题】

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

随机推荐

  1. (转)轻松学习JavaScript三:JavaScript与HTML的结合

    摘自:http://blog.csdn.net/erlian1992 HTML中的JavaScript脚本必须位于<script>与</script>标签之间,JavaScri ...

  2. 从0开始学angularjs-笔记03

    大家好,今天上班第一天,可能大家都不是很想上班吧,我也是一样啦---不想上班就来继续写我的angualrjs教程,造福大家吧!! 今天的主要讲解部分有以下几点:1.演示一个完整的项目结构  2.$sc ...

  3. ae柱状图

  4. SharePoint 2013 版本号和相关问题介绍

    今天查SharePoint 补丁,无意间发现一个非常好的链接,分享给大家! 这里面有SharePoint近期的版本号,而且不断更新,还有每个补丁可能带来的问题,对于服务器经常需要打补丁的那是非常有用, ...

  5. SP2013 SP1(kb28805502)补丁安装测试初体验

    安装完SP1(kb28805502)第一印象是整体页面加载浏览速度非常快了,在笔记本建立的虚拟机能达到肉眼感觉不到卡顿真的是非常快了. 1.新添加了页面个性化设置功能菜单 3.默认访问网站的页面显示, ...

  6. ViewPager的使用小技巧

    1.在ViewPager中默认加载当前屏幕上的界面和左右相邻界面的数据从而实现页面滑动的快速切换.可以通过调用setOffscreenPageLimit(int)方法,定制预加载相邻页面的数目. 2. ...

  7. Java虚拟机JVM学习06 自定义类加载器 父委托机制和命名空间的再讨论

    Java虚拟机JVM学习06 自定义类加载器 父委托机制和命名空间的再讨论 创建用户自定义的类加载器 要创建用户自定义的类加载器,只需要扩展java.lang.ClassLoader类,然后覆盖它的f ...

  8. [转 载] android 谷歌 新控件(约束控件 )ConstraintLayout 扁平化布局

    序 在Google IO大会中不仅仅带来了Android Studio 2.2预览版,同时带给我们一个依赖约束的库. 简单来说,她是相对布局的升级版本,但是区别与相对布局更加强调约束.何为约束,即控件 ...

  9. 旧项目如何切换到Entity Framework Code First

    Entity Framework Code First固然是好东西,然而如果是已经存在的旧有项目,如何简单方便的使用切换呢? 这里介绍一个VS的插件Entity Framework Power Too ...

  10. EMD_MAINTENANCE.EXECUTE_EM_DBMS_JOB_PROCS的删除创建

    在最近的一次优化过程中发现了ORACLE 10g中一个作业EMD_MAINTENANCE.EXECUTE_EM_DBMS_JOB_PROCS执行相当频繁,其实以前也看到过,只是没有做过多的了解和关注. ...