codeforces 672C 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 ≤ 10^9) — 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 ≤ 10^9) — 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.
题意:
给出两个人的初始位置和垃圾桶的位置以及那些瓶子的位置,每个人可以按上面给的步骤进行,问最后两个人走的最少的距离是多少;
思路:
把每个瓶子到垃圾桶和两个人的距离都求出来,再贪心找到最小距离;
最小距离的基础是每个瓶子到垃圾桶距离和的2倍即sum=Σdis[i],然后再选择一个人或者两个人去捡一个瓶子使sum-dis[i]+disa[i]-dis[j]+disb[j]最小,当然这是两个人都去捡的情况,还有就是一个人去捡的情况sum-dis[i]+(disa[i]ordisb[i]);
反正就是找最小的值啦;
本来思路是对的,比赛的时候代码有个地方是b的我直接把a的复制过去忘记改成b了,最后挂在了st上了;
AC代码:
#include <bits/stdc++.h>
/*#include <iostream>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
*/
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e5+;
double fun(double xx,double yy,double fx,double fy)
{
return sqrt((xx-fx)*(xx-fx)+(yy-fy)*(yy-fy));
}
double ax,ay,bx,by,tx,ty,x[N],y[N],dis[N],disa[N],disb[N];
int n;
int main()
{
scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);
scanf("%d",&n);
double ans=;
Riep(n)
{
scanf("%lf%lf",&x[i],&y[i]);
dis[i]=fun(x[i],y[i],tx,ty);
disa[i]=fun(x[i],y[i],ax,ay);
disb[i]=fun(x[i],y[i],bx,by);
ans+=*dis[i];
}
disa[]=;
disb[]=;
dis[]=;
double mmina=,mminb=,s=ans;
int posa=,posb=;
for(int i=;i<=n;i++)
{
if(disa[i]-dis[i]<mmina)
{
mmina=disa[i]-dis[i];
posa=i;
}
if(disb[i]-dis[i]<mminb)
{
mminb=disb[i]-dis[i];
posb=i;
}
}
if(mmina<&&mminb<)
{
if(posa==posb)
{
for(int i=;i<=n;i++)
{
if(i!=posa)
s=min(s,ans-dis[posa]+disa[posa]-dis[i]+disb[i]);
}
for(int i=;i<=n;i++)
{
if(i!=posb)
s=min(s,ans-dis[posb]+disb[posb]-dis[i]+disa[i]);
}
}
else
{
s=ans+mmina+mminb;
}
}
else
{
if(mmina<mminb)
{
s=ans-dis[posa]+disa[posa];
}
else
{
s=ans-dis[posb]+disb[posb];
}
}
printf("%.10lf\n",s);
return ;
}
codeforces 672C C. Recycling Bottles(计算几何)的更多相关文章
- 【18.69%】【codeforces 672C】Recycling Bottles
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 671 A——Recycling Bottles——————【思维题】
Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF671A Recycling Bottles 计算几何
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can ...
- Codeforces Recycling Bottles 模拟
C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- CF 672C Recycling Bottles[最优次优 贪心]
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 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) C. Recycling Bottles
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- Docker如何部署Python项目
Docker 部署Python项目 作者:白宁超 2019年5月24日09:09:00 导读: 软件开发最大的麻烦事之一就是环境配置,操作系统设置,各种库和组件的安装.只有它们都正确,软件才能运行.如 ...
- 洛谷——P1025 数的划分
P1025 数的划分 题目描述 将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序). 例如:n=7,k=3,下面三种分法被认为是相同的. 1,1,5; 1,5,1; 5,1,1; 问有 ...
- 抽球游戏(fwt)
地址:https://nanti.jisuanke.com/t/26017 分析: 现在是给定p,求是否存在这样的数列c,我们可以让p进行fwt变换,然后把点值都三次方根,然后再把得到的点值ufwt成 ...
- 二叉树的层次遍历 II
给定一个二叉树,返回其节点值自底向上的层次遍历. (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历) 例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 ...
- 2716 [Violet 3] 天使玩偶
@(BZOJ)[CDQ分治] Sample Input 100 100 81 23 27 16 52 58 44 24 25 95 34 2 96 25 8 14 97 50 97 18 64 3 4 ...
- 微软CIO如何与业务部门打交道?
微软公司副总裁兼CIO Tony Scott是一个非常智慧的人,他拒绝和CEO讨论IT成本的问题,认为IT不应该谈论成本,而是应该谈论IT提供服务的价值.在满足业务部门需求.为业务部门提供适当的IT支 ...
- centos安装python的虚拟环境和虚拟管理环境
一.大部分介绍的方式是使用pip安装:1.pip install virtualenv 2.pip install virtualenvwrapper 但是我安装完,并没有相应的命令:virt ...
- 【Todo】RTP/RTCP/RTSP/SIP/SDP 等多媒体传输和会话协议
参考 http://m.blog.csdn.net/article/details?id=6211447
- Python的未来和Python的意义 & pypy & JIT
今天在读关于Lisp的文章,感概于这门语言的生命力(Link).同时也读到了关于python的文章,Python之父谈Python的未来(Link) 文章中拿Python和Javascript作比较, ...
- SolidEdge如何自动标注尺寸
1 工具-尺寸-关系助手(必须在编辑草图轮廓状态下,如果你的草图不可编辑,则没有这些选项) 2 框选要自动标注尺寸的东西,这些东西立即变为黄色,然后打对勾 3 选择横纵坐标尺寸原点(其实就是为 ...