A. Recycling Bottles

题目连接:

http://www.codeforces.com/contest/671/problem/A

Description

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:

Choose to stop or to continue to collect bottles.

If the choice was to continue then choose some bottle and walk towards it.

Pick this bottle and walk to the recycling bin.

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 ax, ay, bx, by, tx 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 .

Sample Input

3 1 1 2 0 0

3

1 1

2 1

2 3

Sample Output

11.084259940083

题意

有A和B两个人,地面上有n个空瓶子,现在这A和B要去把这些空瓶子扔到辣鸡桶里面去

每个人同时只能拿一个辣鸡,问你这两人最少走多长,就可以把这些辣鸡全部处理干净?

给你一开始A,B,和辣鸡桶位置

题解:

首先把特殊情况特判掉,就是只由A去捡瓶子,和只有B去捡瓶子的情况

然后只由两个人和路线是 A-瓶子-垃圾桶,B-瓶子-辣鸡桶,其他的都是垃圾桶-瓶子-辣鸡桶

所以我们排序之后,暴力2*2去枚举离A最近的,和离B最近的那个就好了。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+6;
double ax,ay,bx,by,tx,ty;
struct node
{
double x,y;
double dis1,dis2,dis3;
int id;
}p[maxn],p1[maxn],p2[maxn];
int n;
double dis(double x,double y,double x1,double y1)
{
return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
}
bool cmp1(node a,node b)
{
return a.dis1-a.dis3<b.dis1-b.dis3;
}
bool cmp2(node a,node b)
{
return a.dis2-a.dis3<b.dis2-b.dis3;
}
int main()
{
scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y),p[i].id=i;
double ans = 0;
for(int i=1;i<=n;i++)
{
p[i].dis1=dis(p[i].x,p[i].y,ax,ay);
p[i].dis2=dis(p[i].x,p[i].y,bx,by);
p[i].dis3=dis(p[i].x,p[i].y,tx,ty);
ans+=p[i].dis3;
}
ans*=2;
double Ans=1e18;
for(int i=1;i<=n;i++)p1[i]=p[i],p2[i]=p[i];
sort(p1+1,p1+1+n,cmp1);
sort(p2+1,p2+1+n,cmp2);
for(int i=1;i<=100&&i<=n;i++)
{
for(int j=1;j<=100&&j<=n;j++)
{
if(p1[i].id==p2[j].id)continue;
double ans2=ans,ans3=ans,ans4=ans,ans5=ans;
ans2 = ans2 + p1[i].dis1 - p1[i].dis3 + p2[j].dis2 - p2[j].dis3;
ans3 = ans3 + p1[j].dis1 - p1[j].dis3 + p2[i].dis2 - p2[i].dis3;
ans4 = ans4 + p1[i].dis1 - p1[i].dis3;
ans5 = ans5 + p2[j].dis2 - p2[j].dis3;
Ans=min(Ans,ans2);
Ans=min(Ans,ans3);
Ans=min(Ans,ans4);
Ans=min(Ans,ans5);
}
double ans4=ans,ans5=ans;
ans4 = ans4 + p1[i].dis1 - p1[i].dis3;
ans5 = ans5 + p2[i].dis2 - p2[i].dis3;
Ans=min(Ans,ans4);
Ans=min(Ans,ans5);
}
printf("%.12f\n",Ans);
}

Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力的更多相关文章

  1. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  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 Round #352 (Div. 2) C. Recycling Bottles

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

  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. Codeforces Round #352 (Div. 2) ABCD

    Problems     # Name     A Summer Camp standard input/output 1 s, 256 MB    x3197 B Different is Good ...

  6. Codeforces Round #352 (Div. 2)

    模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...

  7. Codeforces Round #352 (Div. 2) (A-D)

    672A Summer Camp 题意: 1-n数字连成一个字符串, 给定n , 输出字符串的第n个字符.n 很小, 可以直接暴力. Code: #include <bits/stdc++.h& ...

  8. Codeforces Round #352 (Div. 2) C

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

  9. Codeforces Round #352 (Div. 2) D. Robin Hood

    题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...

随机推荐

  1. VC++6.0中ClassView中类消失 解决方案[转自网络]

    有时候在VC++6.0中编程会出现这样一个问题,由于对C...View类的操作后,在窗口左边ClassView框中的C...View类会消失,这种操作通常是在C...View类中右击点“Add Win ...

  2. HDU 6061 RXD and functions

    题目链接:HDU-6061 题意:给定f(x),求f(x-A)各项系数. 思路:推导公式有如下结论: 然后用NTT解决即可. 代码: #include <set> #include < ...

  3. ARKit从入门到精通

    ARKit从入门到精通(10)-ARKit让飞机绕着你飞起来 ARKit从入门到精通(9)-ARKit让飞机跟着镜头飞起来 ARKit从入门到精通(8)-ARKit捕捉平地 ARKit从入门到精通(7 ...

  4. docker stack 部署 mysql 5.6

    =============================================== 2018/7/1_第1次修改                       ccb_warlock === ...

  5. 【小程序开发】购物车加减几件demo

    <!-- 主容器 --> <view class="stepper"> <!-- 减号 --> <text class="{{m ...

  6. 数据库-mysql视图

    视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用 一:创建视图 create view view ...

  7. C++模板(Templates)

    模板(template)是泛型编程的基础,"泛型"的含义就是没有不依赖具体的数据类型.模板的引入是为了创建一般性的类(模板类)或者函数(模板函数).典型的容器比如迭代器/算法等是泛 ...

  8. caffe+win7+vs2013 仅CPU环境安装

    笔者对深度学习一直充满着好奇与兴趣,之前学校都是研究图像处理的特征点方式,机器学习使用也不多,别提深度学习了. 在看了李宏毅大佬的PPT后,有了初步的认识,虽然是渣渣电脑,也想自己跑几个深度模型. 说 ...

  9. P2184 【贪婪大陆】

    看到全是线段树或者树状数组写法,就来提供一发全网唯一cdq分治三维偏序解法吧 容易发现,这个题的查询就是对于每个区间l,r,查询有多少个修改区间li,ri与l,r有交集 转化为数学语言,就是查询满足l ...

  10. CCF CSP 201312-3 最大的矩形

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201312-3 最大的矩形 问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i( ...