1003 Emergency

本文介绍了一个城市应急救援团队领导面临的挑战:如何在接到其他城市的紧急求救电话后,迅速带领团队到达现场并沿途召集尽可能多的救援人员。通过使用Dijkstra算法解决单源有权图最短路径问题,实现救援路线的快速规划。

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input Specification:

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N(≤500)N (≤500)N(500) - the number of cities (and the cities are numbered from 0toN−10 to N−10toN1), MMM - the number of roads, C​1C​1C1​​ and C​2​​C​2​​C2 - the cities that you are currently in and that you must save, respectively. The next line contains NNN integers, where the iii-th integer is the number of rescue teams in the iii-th city. Then MMM lines follow, each describes a road with three integers c​1​​,c​2​​c​1​​, c​2​​c1,c2 and LLL, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C​1C​1C1​​ to C​2C​2C2​​.

Output Specification:

For each test case, print in one line two numbers: the number of different shortest paths between C​1C​1C1​​ and C​2C​2C2​​, and the maximum amount of rescue teams you can possibly gather. All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input:

5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1

Sample Output:

2 4


解题思路:

单源有权图最短路径问题,使用Dijkstra算法可解,详见代码


#include <iostream>
using namespace std;
#define INF 100000

int main()
{
	int city[501] = { 0 };	// 节点权重
	int road[501][501];		// 边权重
	bool visit[501] = { 0 };	
	int dist[501] = { 0 };		// 记录最短路径
	int weight[501] = { 0 };	// 记录最大权重和
	int num[501] = { 0 };		// 记录最短路径数量

	int N, M, C1, C2;
	int temp;
	scanf("%d%d%d%d", &N, &M, &C1, &C2);
	for (int i = 0; i < N; i++) {
		scanf("%d", &temp);
		city[i] = temp;
	}
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			road[i][j] = INF;		// 初始化
	int c1, c2, L;
	for (int i = 0; i < M; i++) {
		scanf("%d%d%d", &c1, &c2, &L);
		road[c1][c2] = road[c2][c1] = L;	// 无向图
	}
	
	// 初始化
	for (int i = 0; i < N; i++) 
		dist[i] = road[C1][i];		
	dist[C1] = 0;
	weight[C1] = city[C1];
	num[C1] = 1;
	
	// 核心算法,与寻常Dijkstra算法有所差异 
	for (int i = 0; i < N; i++) {
		int V = -1;
		int MinDist = INF;
		for (int j = 0; j < N; j++) {
			if (visit[j] == false && dist[j] < MinDist) {
				MinDist = dist[j];
				V = j;
			}
		}
		if (V == -1)
			break;
		visit[V] = true;
		for (int W = 0; W < N; W++) {
			if (visit[W] == false && road[V][W] < INF) {
				if (dist[V] + road[V][W] < dist[W]) {
					dist[W] = dist[V] + road[V][W];
					num[W] = num[V];
					weight[W] = weight[V] + city[W];
				}
				else if (dist[V] + road[V][W] == dist[W]) {
					num[W] += num[V];
					if (weight[W] < weight[V] + city[W])
						weight[W] = weight[V] + city[W];
				}
			}
		}
	}
	printf("%d %d", num[C2], weight[C2]);
}
基于蒙特卡洛法的规模化电动车有序充放电及负荷预测(Python&Matlab实现)内容概要:本文围绕“基于蒙特卡洛法的规模化电动车有序充放电及负荷预测”展开,结合Python和Matlab编程实现,重点研究大规模电动汽车在电网中的充放电行为建模与负荷预测方法。通过蒙特卡洛模拟技术,对电动车用户的出行规律、充电需求、接入时间与电量消耗等不确定性因素进行统计建模,进而实现有序充放电策略的优化设计与未来负荷曲线的精准预测。文中提供了完整的算法流程与代码实现,涵盖数据采样、概率分布拟合、充电负荷聚合、场景仿真及结果可视化等关键环节,有效支撑电网侧对电动车负荷的科学管理与调度决策。; 适合人群:具备一定电力系统基础知识和编程能力(Python/Matlab),从事新能源、智能电网、交通电气化等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①研究大规模电动车接入对配电网负荷特性的影响;②设计有序充电策略以平抑负荷波动;③实现基于概率模拟的短期或长期负荷预测;④为电网规划、储能配置与需求响应提供数据支持和技术方案。; 阅读建议:建议结合文中提供的代码实例,逐步运行并理解蒙特卡洛模拟的实现逻辑,重点关注输入参数的概率分布设定与多场景仿真的聚合方法,同时可扩展加入分时电价、用户行为偏好等实际约束条件以提升模型实用性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值