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.

题目链接:http://codeforces.com/contest/672/problem/C


题意:一个广场有n个瓶子,有a,b两个人和一个垃圾桶。捡了瓶子后马上丢到垃圾桶,求两个人的最短路程。

思路:第一次捡瓶子要走的距离就是人到瓶子的距离+瓶子到垃圾桶的距离,第二次捡瓶子要走的距离就是另外一个人到瓶子的距离+瓶子到垃圾桶的距离(或者另外一个人不捡瓶子)。捡其他瓶子要走的距离是垃圾桶到瓶子的距离*2。做差值进行排序。sign1,sign2表示一个人差值最大的两个值。sign3,sign4表示另外一个人差值最大的两个值。总共有5种情况表示人到瓶子的距离+瓶子到垃圾桶的距离(1)sign1;(2)sign3;(3)sign1,sign3;(4)sign1,sign4;(5)sign2,sign3;其中第3种情况要两个瓶子不是同一个。


代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int MAXN = 1e5+, mod = 1e9 + , inf = 0x3f3f3f3f;
typedef long long ll;
const ll INF = (1ll<<);
struct gg
{
double d;
int i;
} sub1[],sub2[];
int cmp(gg a,gg b)
{
return a.d>b.d;
}
int main()
{
int i;
double ax,ay,bx,by,tx,ty;
int n;
double x,y;
double ans=;
scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);
scanf("%d",&n);
for(i=; i<n; i++)
{
scanf("%lf%lf",&x,&y);
double sign1=sqrt((x-ax)*(x-ax)+(y-ay)*(y-ay))+sqrt((x-tx)*(x-tx)+(y-ty)*(y-ty));
double sign2=sqrt((x-bx)*(x-bx)+(y-by)*(y-by))+sqrt((x-tx)*(x-tx)+(y-ty)*(y-ty));
double d=2.0*sqrt((x-tx)*(x-tx)+(y-ty)*(y-ty));
sub1[i].d=d-sign1;
sub2[i].d=d-sign2;
sub1[i].i=sub2[i].i=i;
ans+=d;
}
sort(sub1,sub1+n,cmp);
sort(sub2,sub2+n,cmp);
double sign1=sub1[].d,sign2=sub1[].d,sign3=sub2[].d,sign4=sub2[].d;
int sign1_i=sub1[].i,sign2_i=sub1[].i,sign3_i=sub2[].i,sign4_i=sub2[].i;
double sign,Min=1e15;
sign=ans-sign1;
if(sign<Min) Min=sign;
sign=ans-sign3;
if(sign<Min) Min=sign;
if(sign1_i!=sign3_i)
{
sign=ans-sign1-sign3;
if(sign<Min) Min=sign;
}
sign=ans-sign1-sign4;
if(sign<Min) Min=sign;
sign=ans-sign2-sign3;
if(sign<Min) Min=sign;
printf("%.12f\n",Min);
return ;
}

Codeforces 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   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Centr ...

  3. codeforces 352 div 2 C.Recycling Bottles 贪心

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

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

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

  5. 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 ...

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

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

  7. CF 672C Recycling Bottles[最优次优 贪心]

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

  8. 【模拟】Codeforces 671A Recycling Bottles

    题目链接: http://codeforces.com/problemset/problem/671/A 题目大意: A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃 ...

  9. 【18.69%】【codeforces 672C】Recycling Bottles

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. python之socket编写

    Socket 类型 套接字格式: socket(family,type[,protocal]) 使用给定的地址族.套接字类型.协议编号(默认为0)来创建套接字. socket类型 描述 socket. ...

  2. 了解ES6

    内容: 1.ES6介绍及基础 2.模块.类和继承 3.ES6高级特性 4.Generator和Iterator 5.异步编程 6.函数相关 内容参考:<ES6 标准入门> ES6标准阅读链 ...

  3. 异步请求fetch之初体验

    更好阅读体验可移步我的博客:Blog 导读 传递信息到服务器,从服务器获取信息,是前端发展的重中之重,尤其是现在前后端分离的大前提下,前后端的数据交互是前端的必修科目了.从很久之前到现在,ajax都是 ...

  4. 生存分析与R

    生存分析与R 2018年05月19日 19:55:06 走在码农路上的医学狗 阅读数:4399更多 个人分类: R语言   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...

  5. 网际协议版本4(IPv4)

    IP是一种不可靠的无连接数据报协议-一种尽最大努力交付的服务,尽最大努力一词的意思是IP分组可能会损坏,丢失,失序或延迟到达,并且可能给网络带来拥塞. 网络层的分组称为数据报.是一个可变长度的分组.由 ...

  6. sql 随机取数

    Sql server:      select top 10 * from 表 order by newid()Access:      SELECT top 10 * FROM 表 ORDER BY ...

  7. DDoS攻防战 (一) : 概述

    岁寒 然后知松柏之后凋也 ——论语·子罕 (此图摘自<Web脚本攻击与防御技术核心剖析>一书,作者:郝永清先生)    DDoS,即 Distributed Denial of Servi ...

  8. IOS HTTP访问端口

    Project dyld_sim raised exception class ENetHTTPClientException with message 'Error -1022 accessing ...

  9. UI5-文档-4.17-Fragment Callbacks

    现在我们已经集成了对话框,是时候添加一些用户交互了.用户肯定希望在某个时候再次关闭对话框,因此我们添加一个按钮来关闭对话框并分配一个事件处理程序. Preview The dialog now has ...

  10. python之类的相关知识

    面向对象技术简介 类: 用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例. 类变量:类变量在整个实例化的对象中是公用的.类变量定义在类中且在函数体之 ...