PAT甲级 - 1018 Public Bike Management (30分)

2025海外代理IP深度横评:Bright Data、IPFoxy、SmartProxy等六大服务商实战对比 本文深度横评2025年六大海外代理IP服务商(Bright Data、IPFoxy、SmartProxy、IPIPGO、Kookeey及青果网络),基于实战测试数据,从IP池质量、速度稳定性、性价比等维度进行对比。针对跨境电商、数据爬虫、社交媒体管理等不同业务场景,提供精准的选购指南与避坑建议,帮助企业用户根据自身需求选择最合适的代理IP解决方案。 阅读详情

There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.

The Public Bike Management Center (PBMC) keeps monitoring the real-time capacity of all the stations. A station is said to be in perfect condition if it is exactly half-full. If a station is full or empty, PBMC will collect or send bikes to adjust the condition of that station to perfect. And more, all the stations on the way will be adjusted as well.

When a problem station is reported, PBMC will always choose the shortest path to reach that station. If there are more than one shortest path, the one that requires the least number of bikes sent from PBMC will be chosen.

The above figure illustrates an example. The stations are represented by vertices and the roads correspond to the edges. The number on an edge is the time taken to reach one end station from another. The number written inside a vertex S is the current number of bikes stored at S. Given that the maximum capacity of each station is 10. To solve the problem at S​3​​, we have 2 different shortest paths:

  1. PBMC -> S​1​​ -> S​3​​. In this case, 4 bikes must be sent from PBMC, because we can collect 1 bike from S​1​​ and then take 5 bikes to S​3​​, so that both stations will be in perfect conditions.

  2. PBMC -> S​2​​ -> S​3​​. This path requires the same time as path 1, but only 3 bikes sent from PBMC and hence is the one that will be chosen.

Input Specification:

Each input file contains one test case. For each case, the first line contains 4 numbers: C​max​​ (≤100), always an even number, is the maximum capacity of each station; N (≤500), the total number of stations; S​p​​, the index of the problem station (the stations are numbered from 1 to N, and PBMC is represented by the vertex 0); and M, the number of roads. The second line contains N non-negative numbers C​i​​ (i=1,⋯,N) where each C​i​​ is the current number of bikes at S​i​​ respectively. Then M lines follow, each contains 3 numbers: S​i​​, S​j​​, and T​ij​​ which describe the time T​ij​​ taken to move betwen stations S​i​​ and S​j​​. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print your results in one line. First output the number of bikes that PBMC must send. Then after one space, output the path in the format: 0−>S​1​​−>⋯−>S​p​​. Finally after another space, output the number of bikes that we must take back to PBMC after the condition of S​p​​ is adjusted to perfect.

Note that if such a path is not unique, output the one that requires minimum number of bikes that we must take back to PBMC. The judge's data guarantee that such a path is unique.

Sample Input:

10 3 3 5
6 7 0
0 1 1
0 2 1
0 3 3
1 3 1
2 3 1

Sample Output:

3 0->2->3 0

完了,第一次PAT要凉了

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 510;
const int INF = 1<<30;
struct Node {
	int v;
	int weight;
	Node(int _v, int _weight) : v(_v), weight(_weight) {};
};
int c, n, s, m;
int visited[maxn] = { false };
int dis[maxn];
int weight[maxn];
int need[maxn];
int remain[maxn];
vector<Node> Adj[maxn];
vector<int> path, tempPath;
vector<int> pre[maxn]; //存储前驱结点的数量

void Dijkstra(int start) {//首先保证最短路径
	fill(dis, dis + maxn, INF);
	dis[0] = 0;
	for (int i = 0; i < n; i++) {
		int index = -1;
		int min = INF;
		for (int j = 0; j <= n; j++) {//首先找到最小结点并访问
			if (dis[j] < min && visited[j] == false) {
				min = dis[j];
				index = j;
			}
		}
		if (index == -1) return;
		visited[index] = true;
		for (int j = 0; j < Adj[index].size(); j++) {
			int v = Adj[index][j].v;
			int length = Adj[index][j].weight;
			if (visited[v] == false) {
				if (dis[index] + length < dis[v]) {
					pre[v].clear();
					pre[v].push_back(index);
					dis[v] = dis[index] + length;
				}
				else if (dis[index] + length == dis[v]) {
					pre[v].push_back(index);
				}
			}
		}
	}
}

int MinRemain = INF, MinNeed = INF;
void DFS(int s) {//从目标结点到PMBC进行遍历
	if (s == 0) {//说明到达PMBC,是一条路径
		tempPath.push_back(s);
		int need = 0, remain = 0;
		for (int i = tempPath.size() - 1; i >= 0; i--) {//从后往前枚举,才是路径的正常书匈奴
			int id = tempPath[i];
			if (weight[id] >= 0) {//需要取回车辆
				remain += weight[id];
			}
			else {
				if (remain > abs(weight[id])) {
					remain -= abs(weight[id]);
				}
				else {
					need += abs(weight[id]) - remain; //需要再加车辆
					remain = 0;
				}
			}
		}
		if (need < MinNeed) {
			MinNeed = need;
			MinRemain = remain;
			path = tempPath;
		}
		else if (need == MinNeed && remain < MinRemain) {
			MinRemain = remain;
			path = tempPath; //vector可以直接赋值吗?
		}
		tempPath.pop_back();
		return;
	}
	tempPath.push_back(s);
	for (int i = 0; i < pre[s].size(); i++)
		DFS(pre[s][i]);
	tempPath.pop_back();
}


int main() {

	scanf("%d%d%d%d", &c, &n, &s, &m);
	//weight[0] = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &weight[i]);
		weight[i] -= c / 2;
	}
	for (int i = 1; i <= m; i++) {
		int v1, v2, time;
		scanf("%d %d %d", &v1, &v2, &time);
		Adj[v1].push_back(Node(v2, time));
		Adj[v2].push_back(Node(v1, time));
	}
	Dijkstra(0);//Dijkstra来寻找并记录最短路径,第一标尺
	DFS(s); // DFS来求第二或第三标尺;
	printf("%d ", MinNeed);
	for (int i = path.size() - 1; i >= 0; i--) {//--和++要注意
		printf("%d", path[i]);
		if (i != 0) printf("->");
	}
	printf(" %d", MinRemain);

	return 0;

}

 

携程机票数据爬取实战:使用 Python 获取携程网机票信息 通过本篇博客,我们详细介绍了如何使用 Python 爬取携程网的机票信息,涉及了静态网页爬取(使用 Requests 和 BeautifulSoup)和动态网页爬取(使用 Selenium)两种方法。通过获取的数据,我们不仅能够进行票价分析,还可以构建更为复杂的预测模型或趋势分析工具。爬虫技术不仅能够帮助我们收集有价值的数据,还能够为商业决策提供数据支持。在实际应用中,我们可以结合更多的分析方法,如自然语言处理、图像处理等,进一步提升数据的价值。 阅读详情

相关推荐

告别爆显存!手把手教你为ComfyUI+华为Atlas 300I Duo配置wan2.1视频生成工作流(含CPU-VAE参数)

本文详细介绍了华为Atlas 300I Duo与ComfyUI的深度适配实战,重点优化wan2.1视频生成工作流。从硬件散热改造到软件栈配置,再到ComfyUI专项优化,提供完整的解决方案,显著提升视频生成效率与稳定性,特别适合需要高效文生视频的应用场景。

weixin_26812607的博客 463

PAT甲级A1018 Public Bike Management (30)

There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the ...

vir_lee的博客 303

动态数据脱敏技术分析

在当前国内信息安全热潮中,数据脱敏作为数据安全的重要一环得到了业界的认可与重视。早在2012年,数据脱敏首次作为一个单独的魔力象限由Gartner发布,Gartner在2014年又提出了:按照数据使用场景,将数据脱敏分为静态数据脱敏(Static data masking-SDM )与动态数据脱敏(Dynamic data masking-DDM )。 可能有人望文生义,认为动态数据脱敏一定比静态数据脱敏高级。非也非也,静态or动态,取决于脱敏的使用场景,主要是以使用场景为由来选择合适的数据脱敏的模式。 本

美创科技的博客 4677

[Java] PAT甲级 1018 Public Bike Management

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { static int capacity; static int stations; static int roads; static int target; static i...

我的博客 279

学习笔记【Day 20】鸿蒙PC应用在SD WAN MSTP场景用CodeArts test工具测试过程

多生成树协议(MSTP)作为二层网络高可靠、无环路的核心技术,其在鸿蒙 PC 上的兼容性与稳定性测试尤为重要。本文结合华为云 CodeArts TestPlan 全流程测试管理平台,详细拆解鸿蒙 PC 端 MSTP 功能的测试设计、环境搭建、执行验证。1.测试左移,保障迭代效率CodeArts TestPlan 将 MSTP 测试从后期集成阶段 “左移” 至开发早期,通过可复用用例库与自动化脚本,支持每次代码提交后的快速回归测试,避免网络功能稳定性因迭代被破坏。2.平台化工具破解复杂场景测试难题。

aiyijianghe的博客 1059

多智能体强化学习MATD3算法完整复现与分析

多智能体强化学习MATD3算法复现与分析摘要 MATD3算法是多智能体深度强化学习领域的重要进展,通过改进MADDPG算法,引入双Q学习、延迟策略更新和目标策略平滑等技术,显著提升了算法稳定性。本文完整复现了MATD3算法,详细解析了其数学原理,包括部分可观测马尔可夫博弈模型和TD3核心思想。在实现层面,设计了集中式Critic和分布式Actor的神经网络架构,采用PyTorch框架构建了Actor-Critic网络模块,包含精心设计的权重初始化和训练流程。该算法有效解决了多智能体环境中的非平稳性、信用分配

max500600的博客 532

PAT 甲级 1018 Public Bike Management

DFS+记忆化搜索剪枝 没试过不剪枝会不会超时。 注意点就是没有返回修改这个说法 10 4 4 5 3 5 5 10 0 1 1 0 2 1 1 3 1 2 3 1 3 4 1 这组数据出来的结果是 0 0-&gt;2-&gt;3-&gt;4 5 别的应该没什么问题…判断语句写的好搓 更新 不剪枝直接爆搜也不会超时… #include &lt;iostream&gt...

永仁永仁 351

2025华为OD机试真题+全流程解析+备考攻略+面试技巧+机考经验分享+Java/python/JS/C++/C语言实现

本专栏包含华为 OD 机试最新的 A卷+B卷+C卷+D卷+E卷题库,为全网最全、最新题库,500+真题。每一篇文章都包含了题目描述、解题思路以及实现代码。同时免费提供最新的在线OJ 刷题系统。已有上百名小伙伴通过刷真题题库通过了华为od机考,拒绝一切形式的代考,替考行为!!!以下是本专栏详细内容介绍:本专栏提供在线OJ刷题系统:OJ题库OJ系统注册&使用教程:OJ使用教程其他专栏以及答疑介绍:50+ 高频面试手撕真题,已有上百位小伙伴高频认证。1:机试没过,半年的冷冻期。2:已经订阅过我专栏的同学,推荐新人

MISAYAONE的博客 2226

PAT甲级1018 Public Bike Management (30分)

PAT甲级1018 Public Bike Management (30分) 1018 Public Bike Management There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may ren...

All_Might 274

影像组学文章复现:ITHscore:通过多尺度放射学特征全面定量NSCLC肿瘤内异质性 ----小细胞肺癌肿瘤异质性评分

目的:通过计算机断层扫描(CT)图像量化非小细胞肺癌(NSCLC)的肿瘤内异质性(ITH)。 方法:整合局部辐射特征和全局像素分布模式,开发定量ITH测量-ITHscore。在六个患者队列(n = 1399)中检查ITHscore与肿瘤表型,基因型和患者预后的关联,以验证其在表征ITH方面的有效性。

xxx 1020

【YOLOv8全方位学习手册】第四章 数据增强:从扩充数据到塑造模型的认知边界

"""使用 Albumentations 做自定义增强,兼容 YOLO 格式"""])# 转成 numpy# boxes 必须是 [[x_min,y_min,x_max,y_max], ...]# 在数据加载时调用你可以把集成到 PyTorch 的 Dataset 类里,或使用 Ultralytics 自带的DataLoader。

VectorShift的博客 211

PAT甲级 1018 Public Bike Management (30 分) 题解

\quad这个题目的是要我们能记录所有的最短路径,在这些路径中选择符合题目的那一种输出。我用vector<int> pre[maxn]数组记录符合最短路时节点的前驱节点,用Dijistra获得这个数组。最后用DFS对pre数组进行深搜,找出所有的最短路径来计算需要从中心拿走的自行车数量和需要带回中心的数量,比较输出在从中心带出自行车数量最少的前提下带回中心数量最少的那一种解答,记录此...

qq_40438165的博客 1619

2025年GESP3月认证C++五级真题解析

小 A 有 2n 件物品,小 B 和小 C 想从小 A 手上买走这些物品。对于第 i 件物品,小 B 会以 bi 的价格购买,而小 C 会以 ci 的价格购买。对于所有测试点,保证 1 <= T <= 100, 2 <= g < p <= 10^9, g, p 为整数, p 为质数。对于所有测试点,保证 1 <= n <= 10^5, 0 <= bi, ci <= 10^9, bi, ci 为整数。对于另外 50 % 的测试点,保证 n <= 100000, 0 <= bi, ci <= 10^9。

lan_in的博客 1036

PAT甲级-1018 Public Bike Management (30分)

点击链接PAT甲级-AC全解汇总 题目: There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any o...

卷子的博客 468

数学建模模型总结

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

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

PAT甲级 - 1018 Public Bike Management (30 分)

题目链接:PAT甲级 - 1018 Public Bike Management (30 分) There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any st...

223

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

PAT甲级 1018 Public Bike Management (30分)

1018 Public Bike Management (30分) 题目链接:PAT A 1018 题目大意:城市中有一张共享单车图,下标为0的那个点是共享单车管理中心。完美车站是指一个车站拥有的共享单车数目恰好等于车站最大共享单车数的一半。当某个车站车数等于最大单车数或者为零的时候,中心会调整该车站为完美车站,并且将沿途所有车站调整为完美车站。中心将总是选择距离最近的那一条路径去调整问题车站...

weixin_43684054的博客 427

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

PAT甲级1018 Public Bike Management(30分) (测试点5,7坑)

PAT甲级1018 Public Bike Management (30分)(测试点5,7坑) 一:涉及的知识点 1:dijkstra算法~~(当然堆优化dij也行)~~ 2:dijkstra中的逆向存点法,即有多条同样短的最短路径,并把他们点全部存下来 3:dfs遍历图,不过处理的时候有技巧(测试点5,7)思维题 二:题目链接及其大意 https://pintia.cn/problem-sets/994805342720868352/problems/994805489282433024 There is

m0_50796573的博客 1688

【PAT甲级】个人做题记录之:1018 Public Bike Management (30 分)

PAT甲级圆满考完了,这次也考了一个相对不错的成绩,之后可能就很少刷PAT题库了,慢慢将之前刷题的过程补充记录上来吧 1018 Public Bike Management 题目描述 There is a public bike service in Hangzhou City which provides great convenience to the tourists from all ov...

初见还是重逢的博客 500

【PAT甲级题解记录】1018 Public Bike Management (30 分)

简单来说就是求单源最短路径,但是每个点都有一定数量的自行车,并且给定一个标准车数,我们要从起点到终点一边走一边调整每个点的车数至标准车数。也就是说我们出发时需要拿一定数量的车,在路上遇到多的可以补充进来,少的就要用出去,最终满足使所有车数都标准。 现在要求最短路径下,出发时拿的车数最小的情况,当拿出最小情况一样,就要求拿回车数最小的情况(车多出来了就要拿回去)。这里很坑,他有三个条件,前两个条件相同情况下还会看第三个,感觉姥姥这题出的太折磨了。(菜是原罪)

retr0的博客 436

【Pat 甲级】1018 Public Bike Management (30分)

突然觉得什么都放自己本地不方便 所以还是建了个博客 ------------------------------------------------------------------------ 以下是代码原文和注释 #include <iostream> using namespace std; #define maxv 501 // 题目说车站最多500,加上基地...

a1390415732的博客 197

【PAT甲级】1018 Public Bike Management (30分)

解题过程的小记录,如有错误欢迎指出。 难度:四星(Dijkstra+DFS,难点在DFS中第二权重的比较) 小导航~题目分析注意点我的解题过程思路bug代码dalao的代码借鉴点 题目分析 有一个共享单车总部和各个分部,给出每个分部现有的车辆数,给出要修正的终点,要求将这个终点和沿途的每一个分部都修正为完美车辆数的情况(完美车辆数=车辆存储容量的一半),要求选择的路径时间最短,当时间相同时要求从总部运出的车辆数最少,当时间和从总部运出的车辆数都相同时,要求运回总部的车辆数最少 注意点 修正要求在经过某点的

SpicyChicken的自我修养 470

PAT 甲级 1018 Public Bike Management (30分)

题目 1018 Public Bike Management (30分) There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city. The Public Bi

qq_41001689的博客 187

PAT甲级 1018 Public Bike Management (30 分)

There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city. The Public Bike Management Center (PBMC) keeps mo

qq_44682929的博客 191

PAT真题练习(甲级)1018 Public Bike Management (30 分)

PAT真题练习(甲级)1018 Public Bike Management (30 分) 原题网址:https://pintia.cn/problem-sets/994805342720868352/problems/994805489282433024 There is a public bike service in Hangzhou City which provides great ...

Be Quick & Clever & Lucky 399

PAT甲级1018 Public Bike Management (30 分)

1018Public Bike Management(30分) There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and ret...

Dexter 194

【PAT 甲级】A1018 Public Bike Management (30分)

【Dijkstra+DFS】 总共存在三个标尺——最短路径、PBMC派出去的自行车数、PBMC收回的自行车数,同时还需要求解路径。可以说是非常麻烦了qaq 坑点:所有车站在调整过程中必须一步到位,不能用路径靠后的结点来调整路径靠前的结点。(然原题目里好像并没有说明这件事,不过这个坑点只值5分) 非常好的一组测试点(源自《算法笔记》): //Input 10 4 4 5 4 8 9 0 0 1 1 ...

weixin_42278063的博客 285
上一篇: PAT甲级 - 1021 Deepest Root (25分)
下一篇: PAT甲级简单题最后冲刺
DedicateToAI
博客等级 码龄9年 6粉丝 90原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值