codeforces 671A Recycling Bottles

PT100精密测温电路设计:四线制接法、比例法与ADC选型全解析 温度测量是工业控制与仪器仪表中的基础需求,而铂电阻PT100凭借其良好的稳定性和线性度,成为高精度测温的主流选择。然而,真正实现精密测温并非简单接入ADC即可,信号链路中每一点微小误差都会影响最终结果。理解PT100的电阻-温度特性与恒流源激励原理,是设计高稳定模拟前端的前提。工程实践中,采用比例法可有效抵消电流源漂移,配合四线制开尔文连接彻底消除导线电阻影响,再选用24位Σ-Δ ADC与低温漂参考电阻,即可构建出可靠的高分辨率测量系统。此类设计广泛应用于实验室仪表、精密温控设备及工业现场变送器。本文从底层 阅读详情

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;
}


【WRF-Urban运行】WRF-SLUCM耦合建模参数设置及模拟运行 WRF-SLUCM耦合建模参数设置及模拟运行 阅读详情

相关推荐

告别版本冲突!在Ubuntu 20.04上优雅实现ROS Noetic与ROS2 Foxy双环境切换

本文详细介绍了在Ubuntu 20.04系统上实现ROS Noetic(ROS1)与ROS2 Foxy双环境共存与切换的完整方案。通过智能脚本设计和工作空间隔离,解决了版本冲突问题,帮助开发者高效管理不同ROS版本项目。特别适合需要同时开发ROS1和ROS2应用的机器人开发者。

weixin_28452161的博客 417

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的博客 983

SBM与超效率SBM模型实战:从原始面板数据到MATLAB高效实现

本文详细介绍了SBM模型与超效率SBM模型的核心原理,并提供了从原始面板数据预处理到MATLAB高效实现的完整实战指南。通过具体代码解析,帮助研究者掌握如何利用MATLAB进行数据标准化、模型构建、效率求解及结果可视化,从而精准评估决策单元的相对效率,尤其适用于在高效单元中进一步精细排名的场景。

weixin_29100399的博客 496

【模拟】Codeforces 671A Recycling Bottles

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

PHILIP0917的博客 120

Proteus一体化安装STC15库添加

Proteus一体化安装与STC15库添加指南 本文详细介绍了Proteus 8.9 SP2专业版的一体化安装流程和STC15系列单片机库文件的添加方法。安装过程简单快捷,无需破解,稳定性好。通过将两个库文件(Lib和LIB)复制到Proteus安装目录的DATA/LIBRARY文件夹中,即可实现STC15W4K32S4芯片的仿真功能。文中还提供了新建工程和器件放置的步骤说明,特别指出STC15W4K32S4芯片可兼容仿真其他STC15系列芯片,并附带下载链接获取资源。该教程适用于电子设计初学者和开发者。

#法外狂徒张三的博客 4万+

告别玄学调参:手把手教你用LSTM-AutoEncoder为传感器数据做异常检测(实战篇)

本文详细介绍了LSTM-AutoEncoder在传感器数据异常检测中的工程化实践,包括数据预处理、模型架构设计和生产环境部署策略。通过结合LSTM的时间序列处理能力和AutoEncoder的特征提取优势,该方法能够有效识别温湿度、PM2.5等传感器数据的异常模式,适用于工业物联网和室内空气质量监测等场景。

weixin_29212429的博客 481

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

SAP SD POD 配置与 VLPOD 操作:3步解决发货10件开票7件的业务场景

本文详细解析了SAP SD POD功能在解决发货与开票数量差异中的应用,通过3步配置法实现精准匹配。重点介绍了POD核心逻辑、关键配置步骤及VLPOD操作技巧,帮助企业高效处理易损品运输等复杂场景,提升供应链管理效率。

weixin_30613343的博客 401

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微笑 457

YOLOv8实战:用Labelme标注自定义数据集并训练分割模型(附完整代码)

本文详细介绍了使用Labelme标注自定义数据集并训练YOLOv8实例分割模型的完整流程。从环境搭建、数据标注与格式转换,到模型训练、调优、验证及部署,提供了实战代码和调优建议。文章还探讨了如何结合追踪目标技术,实现视频流中的实例分割与目标追踪,为计算机视觉应用提供了一套可复制的解决方案。

557

消息平台接入实战:Hermes Agent 实现微信/钉钉日常任务自动化的 4 步配置

揭示 Hermes Agent 接入微信/钉钉时高频失效的根本原因——非 API 调用问题,而是上下文边界缺失;详解通过 soul.md 锁定人格基线、skills/ 目录原子化封装技能、CLAUDE.md 控制记忆节奏、Docker 环境适配四步构建可信赖自动化信任链,并给出身份证号过滤、中文标点

weixin_42520239的博客 177

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

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

weixin_30654583的博客 137

2025年开源气象大模型的实现原理与实践指南

气象大模型在人工智能时代实现了革命性突破,通过深度学习技术以更低的计算成本达到甚至超越传统数值天气预报的精度。开源气象大模型的出现使得全球研究者和机构都能参与气象AI的创新。本文详细解析了开源气象大模型的实现原理,包括核心架构、数据准备、训练方法和实际预测流程,并提供了实践指南。核心架构主要采用Transformer、图神经网络和扩散模型,处理多模态数据融合和时空联合建模。数据体系构建涉及数据来源、预处理和增强策略。模型训练关键技术包括损失函数设计、分布式训练优化和训练过程监控。微调与领域适应策略包括迁移学

专注AI大模型,软件混淆,授权 1211

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

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

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

训练3.22(C: Recyling Bottles)

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

urp 156

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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的博客 67

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的博客 1056

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的博客 1030

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的博客 1000

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的博客 932

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的博客 869

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的博客 847

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的博客 808
上一篇: 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、付费专栏及课程。

余额充值
⌂ 换网址