1003 Emergency (25 分)

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) - the number of cities (and the cities are numbered from 0 to N−1), M - the number of roads, C​1​​ and C​2​​ - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c​1​​, c​2​​ and L, 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​1​​ to C​2​​.

Output Specification:

For each test case, print in one line two numbers: the number of different shortest paths between C​1​​ and C​2​​, 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

 本题目大致意思:假设有5个城市,然后每个城市分别有1 2 1 5 3的救援队,把城市看成点,把城市救援队的数量看成点的权重,给了几条路(把路看成边),路的距离其实看成 边的权重,然后src_city,goal_city。然后求最短路径的条数,以及最短路径中点权重最大的值。

  然后是数据结构的准备,5个城市,就需要dis[5],其中dis[src_city]初始化为0,其余都为INF,这个数组的意思是从起点到其他各城市的最小距离。

然后就是算法了:

      第一步:初始化dis[src_city]=0,num[src_city]=1,w[src_city]=weight[src_sity]因为要求最小生成树的条数,所以要多次循环;

      第二步:查找从起点src_city可以到达的点n,并更新dis[n],并保存所有可达点中的最小边值min,把这个最小边值 点标注为visit=true,意为把这个点加入最小树里面;

      第三步:就从这个标注点开始,循环查找它的相邻边,如果遇到它到另一个点n2的边权+min<dis[n2],则更新dis[n2],同时w[n2]=w[n]+weght[n2],同时num[n2]=num[n];如果遇到它到另一个点n2的边权+min=dis[n2],则不更新dis[n2],同时num[n2]=num[n],但比较w[n2]与w[n]+weght[n2]的大小,如果大于的话,更新w[n2];

接下去是代码实现:

  1. #include<stdio.h>
  2. #include<iostream>
  3. using namespace std;
  4. const int INF=100000000;
  5. int city_connection[500][500];
  6. int dis[500],num[500];
  7. int w[500],weight[500];
  8. bool visit[500];
  9. int main(){
  10.     int Ncity,Nload,src_city,goal_city;
  11.     cin>>Ncity>>Nload>>src_city>>goal_city;
  12.     for(int i=0;i<Ncity;i++)
  13.     {
  14.         cin>>weight[i];
  15.     }
  16.     for(int i=0;i<500;i++)
  17.     {
  18.         for(int j=0;j<500;j++)
  19.         {
  20.         city_connection[i][j]=INF;
  21.         }
  22.         dis[i]=INF;
  23.     }
  24.     int a,b,c;
  25.     for(int i=0;i<Nload;i++)
  26.     {
  27.         cin>>a>>b>>c;
  28.         city_connection[a][b]=city_connection[b][a]=c;
  29.     }
  30.     dis[src_city]=0;
  31.     w[src_city]=weight[src_city];
  32.     num[src_city]=1;
  33.     for(int i=0;i<Ncity;i++)
  34.     {
  35.         int u=-1,minn=INF;
  36.         for(int j=0;j<Ncity;j++)
  37.         {
  38.             if(visit[j]==false&&dis[j]<minn)
  39.             {
  40.                 u=j;
  41.                 minn=dis[j];
  42.             }
  43.         }
  44.         if(u==-1) break;
  45.         visit[u]=true;
  46.         for(int m=0;m<Ncity;m++)
  47.         {
  48.             if(visit[m]==false && city_connection[u][m]!=INF)
  49.             {
  50.                 if(dis[m]>dis[u]+city_connection[u][m])
  51.                 {
  52.                     dis[m]=dis[u]+city_connection[u][m];
  53.                     num[m]=num[u];
  54.                     w[m]=w[u]+weight[m];
  55.                 }else if(dis[m]==dis[u]+city_connection[u][m])
  56.                 {
  57.                     num[m]+=num[u];
  58.                     if(w[m]<w[u]+weight[m])
  59.                         w[m]=w[u]+weight[m];
  60.                 }
  61.             }
  62.         }
  63.    }
  64.     printf("%d %d",num[goal_city],w[goal_city]);
  65.     return 0;
  66. }

     

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像析等应用至关重要。以下是深度学习的一些关键概念和组成部: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值