博客
关于我
工厂的烦恼(Floyed)
阅读量:393 次
发布时间:2019-03-05

本文共 878 字,大约阅读时间需要 2 分钟。

工厂的烦恼

Description

  某工厂发现厂里的机器在生产产品时要消耗大量的原材料,也就是说,有大量的原材料变成了废物。因此厂里想找出消耗原材料最大的一条生产线路进行改造,以降低成本。厂里的生产线路是一个有向无环网络,有N台机器分别代表网络中的N个结点。弧< I,j >(i < j)表示原材料从机器i传输到机器j的损耗数量。
Input
第一行是两个整数N,M(N<=100,M<=1000),分别表示网络的结点个数和弧数。第二行至M+1行,每行三个整数A,B,C,表示弧上的损耗为C。
Output
仅一个整数,为损耗最大的线路的损耗量。
Sample Input
5 5
1 2 2
2 4 9
1 3 7
3 4 1
4 5 6
Sample Output
17
分析
这题我用的是Floyed算法
可以参考
注意:
1.要求最大值
2.只要判断a[i][k]和a[k][j]是否存在就行了,不需要再判断a[i][j]是否存在,否则会错(举例:1可以到2,2可以到3,那么1也可以到3,如图:)
在这里插入图片描述
AC代码

#include
using namespace std;int n,m,A,B,C,a[105][105];int main(){ cin>>n>>m; for(int i=1;i<=m;i++) { cin>>A>>B>>C; a[A][B]=C;//有向图 } for(int k=1;k<=n;k++)//标准五行代码 for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j&&i!=k&&j!=k&&a[i][k]!=0&&a[k][j]!=0)//判断是否存在 a[i][j]=max(a[i][j],a[i][k]+a[k][j]);//找权值大的 m=0; for(int i=1;i<=n;i++)//找最大 for(int j=1;j<=n;j++) m=max(m,a[i][j]); cout<

谢谢

转载地址:http://vqpzz.baihongyu.com/

你可能感兴趣的文章
Nmap哪些想不到的姿势
查看>>
Nmap扫描教程之Nmap基础知识
查看>>
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>