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学习笔记2之Tab切换

    1.Tab切换简写版1 页面布局如下: <div id="tab"> <h1 id="title"> <span class=&q ...

  2. javascript --- 原型初探七日谈(一)

    在javascript中,像原型,闭包这样的概念,只要我们能领悟其中的原理,一切都会显得格外清晰与明了. 原型属性(prototype): 下面我们简单定义一个函数 function her(a, b ...

  3. 高清DVI编码器|上海视涛科技

    DVI编码器(E600)简介 高清DVI编码器是上海视涛科技出品的高性能DVI编码产品.该DVI编码器是上海视涛科技完全自主研发,并适用于VGA.DVI.HDMI等信号的编码采集及网络传输的专用硬件设 ...

  4. 如何收缩超大的SharePoint_Config数据库

    前言 在已经运行了2年多的SharePoint服务器上,发现SharePoint_Config的数据库文件越来越大,已经达到90几个GB,收缩可以减小20几个GB,但是一周以后又会恢复到90几个GB大 ...

  5. Web自动化测试 Selenium 1/3

    Selenium 名字的来源 在这里,我还想说一下关于 Selenium 名字的来源,很有意思的 : > : Selenium 的中文名为 “ 硒 ” ,是一种化学元素的名字,它 对 汞 ( M ...

  6. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q84-Q87)

    Question  84You are designing a Web Part for SharePoint 2010 that must be able to be used on any sit ...

  7. iOS中sqlite版本号

    https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS) https://github.com/y ...

  8. Android C代码回调java方法

    本文将讲述下列三种C代码回调java方法 1.c代码回调java空方法 2.c代码回调java int类型参数方法 3.c代码回调javaString类型参数方法 方法都差不多,先看c代码回调java ...

  9. IOS GCD定时器

    提到定时器,NStimer肯定是我们最为熟悉的. 但是NStimer有着很大的缺点,并不准确. 通俗点说,就是它该做他的事了,但是由于其他事件的影响,Nstimer会放弃他应该做的. 而GCD定时器, ...

  10. Atitit.论图片类型 垃圾文件的识别与清理  流程与设计原则 与api概要设计 v2 pbj

    Atitit.论图片类型 垃圾文件的识别与清理  流程与设计原则 与api概要设计 v2 pbj 1. 俩个问题::识别垃圾文件与清理策略1 2. 如何识别垃圾图片1 2.1. 体积过小文件<1 ...