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 ...
随机推荐
- spring-mybatis整合项目 异常处理2
org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/imooc ...
- vue组件封装及父子组件传值,事件处理
vue开发中,把有统一功能的部分提取出来,作为一个独立的组件,在需要使用的时候引入,可以有效减少代码冗余.难点在于如果封装,使用,如何传参,派发事件等,我会采取倒叙的方式进行说明.(本文总结于Vue2 ...
- 《Redis设计与实现》- AOF持久化
1. AOF持久化 Redis AOF 持久化是通过保存Redis服务器所执行的写命令来记录数据库状态的. 2. RDB持久化与AOF持久化的区别 RDB持久化 RDB持久化通过保存数据中的键值对来记 ...
- iOS-重构微博cell模型
一.Frame模型: -------------------WeiboFrame.h-------------------------------------------------- ------- ...
- PHP.25-TP框架商城应用实例-后台2-商品列表页-搜索、翻页、排序
商品列表页 1.翻页 控制器GoodsController.class.php添加方法lst(),显示列表页 在商品模型GoodsModel.class.php类中添加search方法 /** *实现 ...
- JS是如何计算 1+1=2 的?
身为程序员多年,作者今天突然对这件事感到十分好奇了.我问计算机芸芸部件,1+1究竟是如何计算的,他们都茫然的看着我. 打开谷歌浏览器->Console面板,大脑向双手不停发送生物电信号,肌肉细胞 ...
- 对于STM32别名区的理解 (转载)
1. 什么是位段.位带别名区? 2. 它有什么好处? 答1: 是这样的,记得MCS51吗? MCS51就是有位操作,以一位(BIT)为数据对象的操作, MCS51可以简单的将P1口的第2位 ...
- luogu3343 [ZJOI2015]地震后的幻想乡
ref 前置技能是bzoj的串珠子.这种子集dp好神啊qwq. 还有这种钦定点转移子集的方法建议按这题的方法写,不要看串珠子qwq #include <iostream> #include ...
- javascript md5 二次加密 和 java md5 二次加密结果不同
最近研究httpclient post 时遇到了一个问题,很费解. js md5(str) 和 java md5(str),第一次md5 加密结果一样,(当时忽略了大小写问题,java 大写,js小 ...
- 自动化测试(三)如何用python写个一函数,这个函数的功能是,传入一个数字,产生N条手机号,产生的手机号不能重复
本期时间短没来得及写思路,不过我都加了注释,有问题可以@我 import randomimport timedef Phones(number):#生成手机号函数 s = "01234567 ...