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. 原生andriod浏览器回退后dom(click)事件全体失效问题探究

    问题描述 今天同事遇到一个神一样的BUG: 在原生浏览器下,为dom元素绑定一个click事件,其中有个a标签外链,点击a后进入其他页面,点击浏览器后退后,页面点击事件全体失效! 我于是用ios测了下 ...

  2. Moqui简介

    Moqui简介 Moqui是一个生态系统理念,是需要一系列的能够用于构建企业自动化办公的开源软件的组合,如:eCommerce, ERP, CRM, SCM, MRP, EAM, POS, 等等. 架 ...

  3. CSS3滚动条-webkit-scrollbar

    webkit现在支持拥有overflow属性的区域,列表框,下拉菜单,textarea的滚动条自定义样式. 如果你想跳过介绍,直接看demo的话,请点击demo 滚动条是一个伪元素,可以自定义样式.这 ...

  4. 基于SharePoint 2013的论坛解决方案[开源]

    前言 这是自己在空闲时间里,为了提高对SharePoint的认识和熟悉技术,做的一个Demo.可能不尽完善,但是基本功能都已经有了,欢迎大家评论和提意见.自己也会在把源代码放到Github上进行开源, ...

  5. sqlmap笔记

    sqlmap -u "注入链接" --其他参数或命令 (-v 1表示回显出注入过程) [判断指定字段是否存在注入点]当链接包含两个参数时,可用-p开关选择要注入的参数,例检测id是 ...

  6. 用TypeScript开发了一个网页游戏引擎,开放源代码

    最开始学习电脑编程的原动力之一就是想自己编写游戏,一方面很好奇这些游戏是怎么做出来的,另一方面觉得有些地方设计的不合理,希望电脑游戏既能让人玩的有趣,又不浪费时间. 学校五年,毕业十年,学用了十多种编 ...

  7. Understanding theory (1)

    Source: verysmartbrothas.com It has been confusing since my first day as a PhD student about theory ...

  8. Xcode8如何去除控制台多余的打印信息

    Xcode8如何去除控制台多余的打印信息 最近刚使用了Xcode8.遇到了一些问题,总结如下.希望对大家有所帮助. 一.如何去除控制台多余的打印信息. 方法:点击Product----Scheme-- ...

  9. android 切换fragment的两种方式

    使用add方法切换时:载入Fragment1Fragment1 onCreateFragment1 onCreateViewFragment1 onStartFragment1 onResume用以下 ...

  10. iOS开发 JSonKit does not support Objective-C Automatic Reference Counting(ARC)

    有使用JSonKit的朋友,如果遇到“JSonKit does not support Objective-C Automatic Reference Counting(ARC)”这种情况,可参照如下 ...