time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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:

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 .

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

【题解】



这道题求的是两个人总的最短的路程。

而且每次只能拿一个瓶子;

那么。如果两个人都到了垃圾桶的位置;

接下来谁去拿都一样了->完全可以一个人就站在垃圾桶的位置不动。->因为并不是求最短时间!

这样就转换成一个人的问题了;

同时每个垃圾到垃圾桶的距离也是固定的。

预处理一下即可;



dis[0][i]表示垃圾桶到第i个垃圾的距离;

dis[1][i]表示第一个人到第i个垃圾的距离;

dis[2][i]表示第二个人到第i个垃圾的距离;

则一开始预处理出sum=∑2*dis[0][i]

然后分类讨论;

1.第一个人捡起某个垃圾扔到垃圾桶,此后都由他捡。另外一个人至始至终都不动;

2.第二个人捡起某个垃圾扔到垃圾桶,此后都由他捡。另外一个人至始至终都不动;

3.两个人人都捡起一个垃圾(都选离自己最近的),扔到垃圾桶的位置。然后都由一个人捡。另外一个人站在垃圾桶的位置不动;

这里一个人的情况不会出现什么特殊的。

两个人的话,可能选择的是同一个垃圾X;

则处理出离两个人第二远的垃圾;

分别试试让第一个人捡这个X,第二个人捡离自己第二远的垃圾

或者是第一个人捡离自己第二远的垃圾,第二个人捡这个X;

捡垃圾Y的过程

可以表述为

sum-=dis[0][Y];

sum+=dis[t][Y];

t表示的是第几个人;

第一个人捡则加上dis[1][Y];

第二个人捡则加上dis[2][Y]

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#define LL long long using namespace std; const int MAXN = 1e5 + 100;
const double INF = 1e18; int ax, ay, bx, by, tx, ty, n;
int x[MAXN], y[MAXN];
double dis[3][MAXN]; void input(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} double sqr(double x)
{
return x*x;
} double get_dis(double a0, double b0, double a1, double b1)
{
return sqrt(sqr(a0 - a1) + sqr(b0 - b1));
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input(ax); input(ay); input(bx); input(by); input(tx); input(ty);
input(n);
for (int i = 1; i <= n; i++)
input(x[i]), input(y[i]);
for (int i = 1; i <= n; i++)
{
dis[0][i] = get_dis(tx, ty, x[i], y[i]);
dis[1][i] = get_dis(ax, ay, x[i], y[i]);
dis[2][i] = get_dis(bx, by, x[i], y[i]);
}
double sum = 0, fans;
for (int i = 1; i <= n; i++)
sum += 2 * dis[0][i];
//第一个人捡(一定选) 第二个人不捡
double misum1 = INF;
for (int i = 1; i <= n; i++)
{
double tempsum = sum;
tempsum -= dis[0][i];
tempsum += dis[1][i];
misum1 = min(misum1, tempsum);
}
fans = misum1; //第二个人捡(一定选) 第一个人不捡
misum1 = INF;
for (int i = 1; i <= n; i++)
{
double tempsum = sum;
tempsum -= dis[0][i];
tempsum += dis[2][i];
misum1 = min(misum1, tempsum);
}
fans = min(fans, misum1); //第一个个人捡,第二个人也捡
if (n > 1)
{
int num1;
misum1 = INF;
for (int i = 1; i <= n; i++)
{
double tempsum = sum;
tempsum -= dis[0][i];
tempsum += dis[1][i];
if (tempsum < misum1)
{
num1 = i;
misum1 = tempsum;
}
}
int num2;
double misum2 = INF;
for (int i = 1; i <= n; i++)
{
double tempsum = sum;
tempsum -= dis[0][i];
tempsum += dis[2][i];
if (tempsum < misum2)
{
num2 = i;
misum2 = tempsum;
}
}
if (num1 != num2)//捡的是不同的垃圾则可直接求得答案
{
double tempsum = sum;
tempsum -= dis[0][num1];
tempsum -= dis[0][num2];
tempsum += dis[1][num1];
tempsum += dis[2][num2];
fans = min(fans, tempsum);
}
else
{
int tnum1;
misum1 = INF;
for (int i = 1; i <= n; i++)
if (i != num1)
{
double tempsum = sum;
tempsum -= dis[0][i];
tempsum += dis[1][i];
if (tempsum < misum1)
{
tnum1 = i;
misum1 = tempsum;
}
}
int tnum2;
double misum2 = INF;
for (int i = 1; i <= n; i++)
if (i != num1)
{
double tempsum = sum;
tempsum -= dis[0][i];
tempsum += dis[2][i];
if (tempsum < misum2)
{
tnum2 = i;
misum2 = tempsum;
}
} double tempsum = sum;
tempsum -= dis[0][num1];
tempsum -= dis[0][tnum2];
tempsum += dis[1][num1];
tempsum += dis[2][tnum2];
fans = min(fans, tempsum);
tempsum = sum;
tempsum -= dis[0][num1];
tempsum -= dis[0][tnum1];
tempsum += dis[2][num1];
tempsum += dis[1][tnum1];
fans = min(fans, tempsum);
}
}
printf("%.12lf\n", fans);
return 0;
}

【18.69%】【codeforces 672C】Recycling Bottles的更多相关文章

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

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

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

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

  3. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  4. 【codeforces 761E】Dasha and Puzzle

    [题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; ...

  5. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【32.22%】【codeforces 602B】Approximating a Constant Range

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

  8. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. 【84.62%】【codeforces 552A】Vanya and Table

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

随机推荐

  1. Leetcode806.Number of Lines To Write String写字符串需要的行数

    我们要把给定的字符串 S 从左到右写到每一行上,每一行的最大宽度为100个单位,如果我们在写某个字母的时候会使这行超过了100 个单位,那么我们应该把这个字母写到下一行.我们给定了一个数组 width ...

  2. getElementsByClassName兼容低版本浏览器

    var getElementsByClassName = function (searchClass, node,tag) { if(document.getElementsByClassName){ ...

  3. Pyhton 单行、多行注释方法

    一.python单行注释的符号 井号#常被用作单行注释符号,在代码中使用#时,它右边的任何数据都会被忽略,当做是注释.类似c++的// 二.批量.多行注释的符号 多行注释是用三引号: ”’ 注释内容 ...

  4. 反射技术总结 Day25

    反射总结 反射的应用场合: 在编译时根本无法知道该对象或类属于那些类, 程序只依靠运行时信息去发现类和对象的真实信息 反射的作用: 通过反射可以使程序代码访问到已经装载到JVM中的类的内部信息(属性 ...

  5. axios细节之绑定到原型和axios的defaults的配置属性

    把axios绑定到原型 vue开发者一套很好用的实践,一般来说,实践如果能够让大部分人都接受,会逐渐成为一个默认的标准. // 把axios配置到原型上 Vue.prototype.$axios = ...

  6. Revit安装失败怎样卸载重新安装Revit,解决Revit安装失败的方法总结

    技术帖:Revit没有按照正确方式卸载,导致Revit安装失败.楼主也查过网上关于如何解决Revit安装失败的一些文章,是说删除几个Revit文件和Revit软件注册表就可以解决Revit安装失败的问 ...

  7. myeclipse2013在线安装svn

    之前安装svn一直不行.弄了好久.还是在线安装方便. 在Help里面点击Install from Site,然后直接图解: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...

  8. SDUT-2120_数据结构实验之链表五:单链表的拆分

    数据结构实验之链表五:单链表的拆分 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入N个整数顺序建立一个单链表,将该 ...

  9. 走近科学,探究阿里闲鱼团队通过数据提升Flutter体验的真相

    背景 闲鱼客户端的flutter页面已经服务上亿级用户,这个时候Flutter页面的用户体验尤其重要,完善Flutter性能稳定性监控体系,可以及早发现线上性能问题,也可以作为用户体验提升的衡量标准. ...

  10. D - Denouncing Mafia DFS

    这道题其实很简单,求k个到根的链,使得链上的节点的个数尽可能多,如果节点被计算过了,就不能再被计算了,其实我们发现,只要k>=叶子节点,那么肯定是全部,所以我们考虑所有的叶子节点,DFS到根节点 ...