Codeforces Round #352 (Div. 2) C
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.
题意:机器a坐标(ax,ay) 机器b坐标(bx,by) 垃圾桶坐标(tx,ty) 给你n个 垃圾的坐标
机器每次只能把一个垃圾扔进垃圾桶(可以选择不移动) 问你将n个垃圾都扔进垃圾桶 机器a,b经过距离的总和的最小值
题解:只需要判断最优的机器a,b的初始目标垃圾,分别按照s.dis*2-(s.dis+s.disa)=s.dis-s.disa (每个垃圾到垃圾桶的距离的二倍 - 机器a到垃圾的距离+垃圾到垃圾桶的距离) s.dis*2-(s.dis+s.disb)=s.dis-s.disb(每个垃圾到垃圾桶的距离的二倍 - 机器b到垃圾的距离+垃圾到垃圾桶的距离) 排序
取机器a,b最优的前两个可选初始点 a1 a2 b1 b2分三种情况
1. a不动 b动 取b1
2. a动 b不动 取a1
3. a,b都动 (若a,b最优初始点相同,取a1 b2或者取b1 a2) 若不同 取a1 b1
输出 三种情况的最小值;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll __int64
using namespace std;
ll ax,ay,bx,by,tx,ty;
ll n;
double exm1,exm2,ans,ans1,ans2,ans3,anss;
int biao1,biao2;
double distance(ll aa,ll bb,ll cc,ll dd)
{
return sqrt((aa*1.0-cc*1.0)*(aa*1.0-cc*1.0)+(bb*1.0-dd*1.0)*(bb*1.0-dd*1.0));
}
double minx( double ss, double tt)
{
if(ss<tt)
return ss;
return tt;
}
struct node
{
int x,y;
double dis;
double disa;
double disb;
int flag;
}N[],M[],a1,a2,b1,b2;
bool cmp1(struct node s,struct node t)
{
if(s.dis+t.disa>t.dis+s.disa)
return true;
return false;
}
bool cmp2(struct node s,struct node t)
{
if(s.dis+t.disb>t.dis+s.disb)
return true;
return false;
}
int main()
{
scanf("%I64d %I64d %I64d %I64d %I64d %I64d",&ax,&ay,&bx,&by,&tx,&ty);
scanf("%I64d",&n);
ll xx,yy;
for(ll i=;i<=n;i++)
{
scanf("%I64d %I64d",&xx,&yy);
N[i].x=xx;
N[i].y=yy;
N[i].dis=distance(xx,yy,tx,ty);
N[i].disa=distance(xx,yy,ax,ay);
N[i].disb=distance(xx,yy,bx,by);
M[i].x=N[i].x;
M[i].y=N[i].y;
M[i].dis=N[i].dis;
M[i].disa=N[i].disa;
M[i].disb=N[i].disb;
N[i].flag=i;
M[i].flag=i;
}
ans1=;
for(ll i=;i<=n;i++)
ans1=ans1+N[i].dis*2.0;
ans2=ans1;
ans3=ans1;
sort(N+,N+n+,cmp1);
sort(M+,M+n+,cmp2);
a1=N[];a2=N[];
b1=M[];b2=M[];
if(a1.x==b1.x&&a1.y==b1.y)
{
exm1=a1.dis-a1.disa+b2.dis-b2.disb;
exm2=a2.dis-a2.disa+b1.dis-b1.disb;
if(exm1>exm2)
ans=exm1;
else
ans=exm2;
}
else
ans=a1.dis-a1.disa+b1.dis-b1.disb;
ans=ans1-ans;
ans2=ans2-N[].dis+N[].disa;
ans3=ans3-M[].dis+M[].disb;
anss=minx(ans,ans2);
anss=minx(anss,ans3);
printf("%.12f\n",anss);
}
Codeforces Round #352 (Div. 2) C的更多相关文章
- Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心
题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...
- Codeforces Round #352 (Div. 2) D. Robin Hood
题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...
- Codeforces Round #352 (Div. 2) D. Robin Hood (二分答案)
题目链接:http://codeforces.com/contest/672/problem/D 有n个人,k个操作,每个人有a[i]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差 ...
- Codeforces Round #352 (Div. 1) B. Robin Hood 二分
B. Robin Hood 题目连接: http://www.codeforces.com/contest/671/problem/B Description We all know the impr ...
- 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) B. Different is Good 水题
B. Different is Good 题目连接: http://www.codeforces.com/contest/672/problem/B Description A wise man to ...
- Codeforces Round #352 (Div. 2) A. Summer Camp 水题
A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...
- 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) B - Different is Good
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to b ...
随机推荐
- 最短路径之迪杰斯特拉算法(Java)
1)Dijkstra算法适用于求图中两节点之间最短路径 2)Dijkstra算法设计比较巧妙的是:在求源节点到终结点自底向上的过程中,源节点到某一节点之间最短路径的确定上(这也是我之前苦于没有解决的地 ...
- c++右值引用
右值 右值是相对与左值来说的. 左值是以变量的形式存在,指向一个指定的内存,可以对它取地址.右值就是不指向任何地方,它是暂时和短命的,不能对它取地址. 右值引用 把临时的.生命周期短的值,绑定到一个变 ...
- 笔记-ORM-sqlalchemy
笔记-ORM-sqlalchemy 1. ORM 1.1. ORM框架简介 对象-关系映射(Object/Relation Mapping,简称ORM),是随着面向对象的软件开发方法发 ...
- java线程安全(单例模式)(转载)
原文链接:http://www.jameswxx.com/java/%E8%AF%B4%E8%AF%B4%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F/ 单例模式?多么简单! ...
- Android面试收集录9 IntentService详解
一. 定义 IntentService是Android里面的一个封装类,继承自四大组件之一的Service. 二.作用 处理异步请求,实现多线程 三. 工作流程 注意:若启动IntentService ...
- HDU 4576 Robot(概率dp)
Robot Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Sub ...
- pg数据库数据表异常挂起
pg数据库即是PostgreSQL数据库. 前几天在一个Java项目中,出现运行Java程序后,pg数据库的数据表异常挂起.而且是在某台电脑上出现的,重装数据库也没用,其它电脑未能复现,是个很奇怪的现 ...
- Windows下zookeeper注册中心的安装和启动
zookeeper的安装支持单机模式和集群模式 下载地址:http://www.apache.org/dyn/closer.cgi/zookeeper/,当前稳定版本为3.4.8 单机模式 修改zoo ...
- CodeIgniter学习笔记一:基本结构、控制器、视图、超级对象、数据库
一.基本结构 CodeIgniter3.0.0解压后有8个文件,分别是: application:项目文件 system:系统(框架)文件,为方便升级,不建议修改 user_guid:用户手册,不需要 ...
- 在iis上部署asp.net mvc2.0
mvc2.0是vs2010自带的,在开发环境下可以直接部署在iis中.在生产环境下,如果不能找到正确的mvc2.0版本,可以直接把开发环境下的System.Web.Mvc.dll拷贝过去使用. 1, ...