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. 发测试 HTML/FILE/MYSQL/动态 20151120

    NilCMS几种页面输出方式: 1.直接生成html.不进行php处理. 2.生成文件缓存.针对于URL中单个目录文件过多,不利于管理.只进行PHP处理,不连接mysql. 3.生成mysql缓存.数 ...

  2. web基础

    1.认识webapp程序?     请求方式不同:基于事件触发------基于http协议下的http请求和http响应.点击百度一下-----发送了请求:不仅会携带问题,ip地址,主机号.请求是客户 ...

  3. Web前端开发工具总结

    前端开发工具: web前端开发乃及其它的相关开发, 推荐sublime text, webstorm(jetbrains公司系列产品)这两个的原因在于,有个技术叫emmet, http://docs. ...

  4. Marketing with Microsoft Dynamics CRM IDEA CONFERENCE

    Object:Marketing with Microsoft Dynamics CRM  IDEA CONFERENCE  24 SEPTEMBER 2015 | BROADCAST ONLINE ...

  5. 【数据库】MySQL的安装与简单使用

    首先我们要下载Mysql的安装包,大家可以到http://mysql.com官网中根据自己的电脑系统版本下载 也可以点击 MySQL资源 下载 密码:btuu 建议下载5.7以上的版本,因为省掉了许多 ...

  6. Xcode cannot launch because the device is locked.

    When you plug in your iPhone, it will ask you to trust the computer. If you already trust and unlock ...

  7. 按钮在cell上的高亮状态出现的慢

    在单元格上放一个全屏长的按钮  高度不是cell的高度    当点击cell上的按钮的时候   按钮的高亮状态会出现的比较慢   因为按钮设置的就是touchUpInside   所以当你向下按的时候 ...

  8. 【读书笔记】iOS网络-保护网络传输

    一,验证服务器通信. 二,HTTP认证. 手机银行应用有两种认证模式:标准验证与快速验证.标准验证只是提示用户输入用户名与密码,而快速验证则让用户注册设备,然后使用PIN进行验证,每次验证时无需用户名 ...

  9. 网络热恋之json解析

    现在的app开发很少有用到XML解析的了,主流的则是JSON. // // ViewController.m // CX-JSON解析(三方JSONKit-master) #import " ...

  10. SSH 框架

    SSH是 struts+spring+hibernate的一个集成框架,是目前较流行的一种web应用程序开源框架.是把多个框架(Struts.Spring以及Hibernate)紧密的结合在一起,用于 ...