codeforces 671A Recycling Bottles

基于Lora的一主多从监测与控制系统 题目:基于Lora的远程农业监测与控制系统 目的:通过Lora子节点采集好各种传感器的信息,发送给汇聚节点,汇聚节点将数据通过ESP8266上传至云端,使用了微信小程序进行监测与控制 阅读详情

A. Recycling Bottles
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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:

  1. Choose to stop or to continue to collect bottles.
  2. If the choice was to continue then choose some bottle and walk towards it.
  3. Pick this bottle and walk to the recycling bin.
  4. 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
Note

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]);

反正就是找最小的值啦;



#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

const int maxn = 100000;
int n;
double ax, ay, bx, by, tx, ty; //刚开始就用double,用int会越界
double dis[maxn + 10], disa[maxn + 10], disb[maxn + 10];

double getdis(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
	scanf("%lf%lf%lf%lf%lf%lf", &ax, &ay, &bx, &by, &tx, &ty);
	scanf("%d", &n);
	double ans = 0, s;
	for (int i = 1; i <= n; i++) {
		double x, y;
		scanf("%lf%lf", &x, &y);
		dis[i] = getdis(x, y, tx, ty);
		disa[i] = getdis(x, y, ax, ay);
		disb[i] = getdis(x, y, bx, by);
		ans += dis[i] * 2;
	}
	s = ans;
	double minna = 999999999999, minnb = 999999999999;
	int posa = 1, posb = 1;
	for (int i = 1; i <= n; i++) {
		if (disa[i] - dis[i] < minna) {
			minna = disa[i] - dis[i];
			posa = i;
		}
		if (disb[i] - dis[i] < minnb) {
			minnb = disb[i] - dis[i];
			posb = i;
		}
	}
	dis[0] = disa[0] = disb[0] = 0;
	//当minna < 0时disa[i] < dis[i],也就是说第一次去捡的时候
	//disa[i] + dis[i] < dis[i] * 2,即从A的位置过去捡起来再丢进垃圾桶
	//比以后从垃圾桶出发折返一次路径要短,B同理
	if (minna < 0 && minnb < 0) {
		if (posa == posb) {
			for (int i = 0; i <= n; i++) {
				if (i != posa) {
					s = min(s, ans - dis[posa] + disa[posa] - dis[i] + disb[i]);
				}
			}
			for (int i = 0; i <= n; i++) {
				if (i != posb) {
					s = min(s, ans - dis[posb] + disb[posb] - dis[i] + disa[i]);
				}
			}
		}
		else {
			s = s + minna + minnb;
		}
	}
	else {
		//这时候说明有,假如是minna >= 0
		//disa[i] >= dis[i],也就是第一次A的位置没有对最后结果做出积极的作用
		//但是第一步再怎么样都不能不捡东西直接去垃圾桶,不然最后总路径肯定更长
		//无奈之下只好只让A或者B中一个人一直捡完,另一个人打酱油不动
		//选捡第一个的时候走的路径尽量短的那个人去捡
		if (minna < minnb) {
			s = s + minna;
		}
		else {
			s = s + minnb;
		}
	}
	printf("%.12f\n", s);
	return 0;
}


FLACS-CFD 气云爆炸模拟全流程工况构建指南:从泄漏到爆炸 摘要: 本文详细介绍了使用FLACS-CFD模拟气云爆炸的全流程构建方法,重点解决泄漏模拟到爆炸模拟的气云文件传递问题。核心步骤包括: 项目规划:明确泄漏源(甲烷管道腐蚀泄漏)和爆炸场景,建立标准目录结构; 网格设计:泄漏与爆炸模拟需采用兼容的网格,爆炸域应为泄漏域的子区域且网格划分一致; 泄漏模拟配置:通过.inp文件定义几何、网格、风场、燃料及泄漏源参数,确保输出爆炸所需的气云文件(*.uni/*.fla); 关键设置:统一燃料名称、时间点匹配、路径正确性,避免版本兼容性问题。 阅读详情

相关推荐

Hypermesh联合ABAQUS—Sets的建立和编辑

打开part copy对话框在对话框的最上面位置可以输入copy后的名称,然后将最下面的Separate disconnected regions into parts(将不连续的区域分割成parts)选项的前面方框勾选上。打开abaqus软件界面,File→import→model,将file filter选为inp格式,找到要导入的有限元文件,单击OK导入文件。HyperWorks新建Set时,会在Model Browser显示,打开Create Set对话框显示详细信息。快捷键,高亮set的内容。

动力资料屋的博客 1289

Codeforces 671A Recycling Bottles

题目 C. Recycling Bottles 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

Druning的博客 982

基于TMS320F28034的SCI技术简介

28034的SCI没有接入DMA总线,不过它的收发都有4级的FIFO,在一定程度上也能够缓解cpu的压力。 本文的设计思想如下: 接收:通过中断的方式,4级FIFO满后在中断里将RXDATA出栈。不过就存在这种情况,发送端发出的数据未必能填满4级FIFO,然而此时配置的是4级FIFO触发中断,所以这种情况下中断无法及时地触发。怎么办? 本文的做法是在主程序下循环读取FIFO。这样就可以确保在数据高速传输时,通过中断和主程序及时和有效地接收到总线的数据。(不过当总线波特率较低时可能中断是几...

weixin_48388779的博客 1406

【模拟】Codeforces 671A Recycling Bottles

题目链接:   http://codeforces.com/problemset/problem/671/A 题目大意:   A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃圾桶最少走多远。一次只能拿一个垃圾。允许一个人走另一个人停下来。   (1 ≤ n ≤ 100 000)(0 ≤ xi, yi ≤ 109) 题目思路:   【模拟...

PHILIP0917的博客 118

【机械视觉】Halcon—【二、Halcon算子全面介绍(超详细版)】

Halcon 的算子(operators)按照功能被系统性地划分为多个类别,官方文档中目前(Halcon 22.11 版本)共有 19 个主分类,每个主分类下还有若干子分类。 本人在此对这19个分类的常用核心算子进行了一系列的总结,且本人在文章最后还总结了一些案例经验。 注意: ​​​​​​​跨分类调用:某些算子可能在多个分类中,但官方文档中会明确其主分类。 例如: read_image(文件操作)常被其他分类(如图像处理)的示例调用,但其核心功能是文件读取。

qq_3517289697的博客 3912

win2012 r2 + IIS8.5 伪静态设置脚本映射

win2012 r2 + IIS8.5 伪静态设置脚本映射,网站用的.net fromwork 2.0 ,应用程序池设置了32位支持

xueking87的专栏 3239

Codeforces 671A Recycling Bottles 【dp】

题目链接:Codeforces 672C Recycling Bottles C. Recycling Bottles time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output It was recycling day in Keko

世界很大 521

西门子S7-1200与S7-200SMART的PROFINET通讯实战:从GSD文件生成到数据监控

本文详细解析了西门子S7-1200与S7-200SMART之间实现PROFINET通讯的完整实战流程。核心内容包括将S7-200SMART配置为智能IO设备、生成并安装GSD文件、在TIA Portal中进行网络组态与地址映射,最终实现双向数据交换与监控。该方案为整合新旧设备、构建灵活高效的工业自动化系统提供了可靠路径。

weixin_29271263的博客 245

CodeForces 671A Recycling Bottles

A. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To c

Calm微笑 453

【ArcGIS】07 ArcHydroTools对COM组件的调用返回了错误

在用Arc Hydro Tools提取流域时,在DEM Reconditioning时可能会遇到这个问题: 经过摸索,发现了问题产生的原因: 结果文件保存在了有中文的路径中。 解决的办法: 首先,把ArcGIS切换成英文版 搜索ArcGlS Administrator,以管理员方式打开 点击高级,选择语言为English 其次,新建mxd文档 删除原来的mxd文档,新建mxd文档,放置原来的图层文件。如果不这样做,最后一步的Map Name还会是“图层”这两个汉字。 最后,设置Arc Hydro T

记录专业模型开发、算法程序设计、软件学习笔记、生活日志。 4918

「PAT乙级真题解析」Basic Level 1034 有理数四则运算 (问题分析+完整步骤+伪代码描述+提交通过代码)

题设给定两个有理数, 要求输出这两个有理数的和、差、积、商。 如果只是这样, 则问题很简单, 但是题设要求输出的每个有理数必须是最简形式. **所以本题的一个重点是如何将有理数转为题设要求的有理数.**

过美好生活,做高效程序员 3129

Codeforces 671A Recycling Bottles(贪心+思维)

题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到箱子里面去,一次只能拿一个瓶子,求把全部瓶子捡完之后的距离总和最小。解题思路:开始有两个起点A,B。除了从A或B出发拿瓶子并回到箱子距离不确定,其他时候肯定要从箱子到瓶子再回到箱子,距离就...

weixin_30654583的博客 137

在jetson上对fastdeploy进行源码编译(完整版)

在大多数Linux发行版中,你可以使用包管理器安装Python开发包。根据jetpack的版本选择对应的推理库版本。在~/.bashrc中写入这三行。

如果想成为中心,那么就到中心去吧。 677

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

A. Recycling Bottles(坐标距离和转化)

https://codeforces.com/problemset/problem/671/A 题目描述 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 coordin

代码笔记本 286

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

训练3.22(C: Recyling Bottles)

cf 671A 题目:http://codeforces.com/problemset/problem/671/A 题意:有A,B两人在捡瓶子。共有n个瓶子,回收箱只有一个,,记作 t 。给出A,B,n个瓶子以及回收箱的坐标位置,求捡完所有垃圾后两人所走过的最短路程。 且,捡瓶子有一定规则:要么不捡,要么直接走直线去捡,捡了之后也必须走直线直接去回收箱。 题解:假设人从决定去捡瓶子k开始到把瓶子k...

urp 155

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力

A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles ...

weixin_30878361的博客 65

Codeforces Round #335 606A - Magic Spheres

A. Magic Spheres time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Carl is a beginner magician. He has a blue

EventQueue的博客 1054

codeforces 659E New Reform

E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectio

EventQueue的博客 1028

Codeforces Round #335 (Div. 2) 605A Sorting Railway Cars

A. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An infinitely long railway has a tr

EventQueue的博客 996

codeforces723C Polycarp at the Radio 英语阅读题

C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Polycarp is a music editor at the

EventQueue的博客 935

codeforces 676C Vasya and String 前缀数组+二分查找

C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string o

EventQueue的博客 931

codeforces C. Lorenzo Von Matterhorn

C. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Barney lives in NYC. NYC has infin

EventQueue的博客 867

codeforces 676B Pyramid of Glasses 递归

B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mary has just graduated from one well-known Univ

EventQueue的博客 842

codeforces 651B Beautiful Paintings

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for th

EventQueue的博客 806
上一篇: Codeforces Round #352 (Div. 2) B. Different is Good
下一篇: ACM中JAVA的使用
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值