Problem-I
来源:互联网 发布:kingcms php 编辑:程序博客网 时间:2024/04/30 23:29
概述:有一些t-shit,然后需要运到不同城市的地方,给出城市之间需要的时间,问所需最短时间。
思路:非常简单的最短路问题,用floyd算法解决。确定好输入情况,套用基本框架即可。
感想:非常简单的一道题,用算法框架即可解决。
#include<iostream>#include<string.h>#include<fstream>#include<stdio.h>#include<algorithm>#include<cmath>const int N = 105;int map[N][N];int n, m;const int INF = 999999;int min(int a, int b){if (a < b)return a ;else return b;}void floyd(){int i, j, k;for (k = 1;k <= n;k++)for (i = 1;i <= n;i++)for (j = 1;j <= n;j++) map[i][j] = min(map[i][j], map[i][k] + map[k][j]);}void init(){for (int i = 1;i <= n;i++){map[i][i] = INF;for (int j = i + 1;j <= n;j++)map[i][j] = map[j][i] = INF;}}using namespace std;int main(){//ifstream cin("in.txt");while (cin >> n >> m&&n + m){init();while (m--){int x, y, z;cin >> x >> y >> z;map[x][y] = map[y][x] = z;};floyd();cout << map[1][n] << endl;}return 0;}
0 0
- Problem I
- Problem I
- Problem I
- Problem I
- Problem I
- Problem I
- Problem-I
- Problem I
- Problem B & Problem I
- Problem : 1022 ( Train Problem I )
- Problem I : Palindrome Partitioning I
- 1022 Train Problem I
- HDU1022 Train Problem I
- 1997: Simple Problem I
- Train Problem I
- 1022:Train Problem I
- 1022 Train Problem I
- HDU1022 Train Problem I
- Android中的网络编程2——Retrofit
- Android 之 IPC 进程通信全解析 -- 墙裂推荐
- ubuntu中配置jdk环境
- git克隆代码到本地
- ReactJs入门教程
- Problem-I
- JavaScript概述
- 专题四 第八道题
- ThreadLocal学习笔记
- std::move -- 强制转化为右值
- springmvc数据绑定
- 使用WPF创建SignalR服务端
- hibernate映射属性
- ASCII码表完整版