Codeforces Round #352 (Div. 2) C. Recycling Bottles
2 seconds
256 megabytes
standard input
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:
- 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.
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.
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
.
3 1 1 2 0 0
3
1 1
2 1
2 3
11.084259940083
5 0 4 2 2 0
5
5 2
3 0
5 5
3 5
3 3
33.121375178000
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.
题目大意:平面上有n个垃圾,每个垃圾有个坐标,现在A 和B想把垃圾放到垃圾箱内,A或B至少有一个人得捡垃圾这样才能把所有垃圾捡完。
解题思路:分析我们可以发现,当a或b走到垃圾桶后,后面所用的时间是不变的,即 Σ垃圾桶到垃圾的距离的2倍。
暴力。为了写代码方便,先处理出垃圾到a的距离disa[i] 垃圾到b的距离disb[i] 垃圾到垃圾桶的距离dis[i]。
暴力3种情况。(1)只有A在捡垃圾 (2)只有B在捡垃圾
(3)A,B都捡垃圾.。 ans=sum+min(dis[id1]-disa[id1])+min(dis[id2]-disb[id2] ) (id1!=id2)。
/* ***********************************************
Author :guanjun
Created Time :2016/5/12 19:34:55
File Name :cf352c.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100100
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; double dist(double a,double b,double c,double d){
return sqrt((a-c)*(a-c)+(b-d)*(b-d));
}
double disa[maxn];
double disb[maxn];
double dis[maxn];
double disk[maxn];
double Min1,Min2,ans;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
double a,b,c,d,e,f;
int n;
double x,y;
while(cin>>a>>b>>c>>d>>e>>f>>n){
double sum=;
for(int i=;i<=n;i++){
scanf("%lf %lf",&x,&y);
disa[i]=dist(a,b,x,y);
disb[i]=dist(c,d,x,y);
dis[i]=dist(e,f,x,y);
sum+=dis[i];
}
sum*=2.0;
Min1=Min2=1e19;
for(int i=;i<=n;i++){
Min1=min(Min1,disa[i]-dis[i]);
Min2=min(Min2,disb[i]-dis[i]);
}
ans=min(sum+Min1,sum+Min2);//当有一个不动的时候
int id1=-,id2=-;
Min1=Min2=1e19;
for(int i=;i<=n;i++){
if(disb[i]-dis[i]<Min1){
Min1=disb[i]-dis[i];
id1=i;
}
}
for(int i=;i<=n;i++){
if(disa[i]-dis[i]<Min2&&(id1!=i)){
Min2=disa[i]-dis[i];
id2=i;
}
}
ans=min(ans,sum+Min1+Min2);
Min1=Min2=1e19;
for(int i=;i<=n;i++){
if(disa[i]-dis[i]<Min1){
Min1=disa[i]-dis[i];
id1=i;
}
}
for(int i=;i<=n;i++){
if(disb[i]-dis[i]<Min2&&(id1!=i)){
Min2=disb[i]-dis[i];
id2=i;
}
}
ans=min(ans,sum+Min1+Min2);
printf("%.10f\n",ans);
}
return ;
}
Codeforces Round #352 (Div. 2) C. Recycling Bottles的更多相关文章
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- 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 ...
- Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心
题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...
- codeforces 352 div 2 C.Recycling Bottles 贪心
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #352 (Div. 2) ABCD
Problems # Name A Summer Camp standard input/output 1 s, 256 MB x3197 B Different is Good ...
- Codeforces Round #352 (Div. 2)
模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...
- Codeforces Round #352 (Div. 2) (A-D)
672A Summer Camp 题意: 1-n数字连成一个字符串, 给定n , 输出字符串的第n个字符.n 很小, 可以直接暴力. Code: #include <bits/stdc++.h& ...
- Codeforces Round #352 (Div. 2) C
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #352 (Div. 2) D. Robin Hood
题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...
随机推荐
- ZOJ - 3816 Generalized Palindromic Number dfs
Generalized Palindromic Number Time Limit: 2 Seconds Memory Limi ...
- luogu P3865 【模板】ST表
题目背景 这是一道ST表经典题——静态区间最大值 请注意最大数据时限只有0.8s,数据强度不低,请务必保证你的每次查询复杂度为 O(1)O(1) 题目描述 给定一个长度为 NN 的数列,和 MM 次询 ...
- JavaSE的包装类,自动装箱和自动拆箱 ,字符窜转换,toString(),equals(), hashCode()的区别
一.基本数据类型和包装类 包装类均位于Java.lang包,包装类和基本数据类型的对应关系如下表所示: Primitive-Type Wrapper-Class byte ...
- getpixel 取色
HWND hwnd = ::FindWindow(NULL,"<天龙八部OL>"); CRect rect; CString strTmp; if (hwnd != N ...
- MySQL的内存表(转)
说明:MySQL内存表可以提升一些临时业务的查询,比如做Session的共享,一些类似缓存的数据等. “内存表”顾名思义创建在内存中的表,真是这样吗?其实不然,MySQL的内存表,表结构创建在磁盘上, ...
- 用JS过滤Emoji表情的输入
本文为原创,转载请注明出处: cnzt 文章:cnzt-p http://www.cnblogs.com/zt-blog/p/6773854.html 在前端页面开发过程中,总会碰到不允许 ...
- XP操作系统设置:[82]关机快捷键
磨镰刀不少割麦,掌握了快速关机的多种方法,在尴尬的时候说不定还真能派上用场呢. 工具/原料 手提电脑.台式电脑.Windows 操作系统. 方法一: 1 Windows XP 操作系统中有 ...
- 全卷积网络FCN详解
http://www.cnblogs.com/gujianhan/p/6030639.html CNN能够对图片进行分类,可是怎么样才能识别图片中特定部分的物体? (图像语义分割) FCN(Fully ...
- BUPT复试专题—统计字母(2008)
题目描述 给定一个只有小写英文字母组成的字符串,串长为n.请你编写程序求出这个字符串中出现次数最多的字母. 输入 输入的第一行为t(0 < t < 10),表示有t组测试用例.对于每组测试 ...
- malloc动态分配多维数组
下面试自己写的三个测试程序,如果看懂了基本上动态分配多维数组就没什么问题啦:重点 1:深刻理解多维数组的概念,多维数组在内存中的分配情况,基本上动态分配也没什么问题的.然后还要注意一点的就是,释放是分 ...