125 - Numbering Paths 解题报告
来源:互联网 发布:java滑动验证码源代码 编辑:程序博客网 时间:2024/05/16 08:42
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=61
floyd的题,稍微有点变化,直接上代码:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int map[35][35];
int N, m = 0;
int caseid = 0;
while(cin>>N)
{
m = 0;
memset(map, 0, sizeof(map));
int c1, c2;
for(int i = 0; i < N; ++i)
{
cin>>c1>>c2;
map[c1][c2] = 1;
m = max(m, c1);
m = max(m, c2);
}
for(int i = 0; i <= m; ++i)
for(int j = 0; j <= m; ++j)
for(int k = 0; k <= m; ++k)
{
if(map[j][k] != 0 && map[k][j] != 0)
map[j][k] = map[k][j] = -1;
else if((map[j][i] == -1 && map[i][k] != 0) || (map[j][i] != 0 && map[i][k] == -1))
map[j][k] = -1;
else
map[j][k] += map[j][i] * map[i][k];
}
cout<<"matrix for city "<<caseid<<endl;
for(int i = 0; i <= m; ++i)
{
int j;
for(j = 0; j <= m-1; ++j)
cout<<map[i][j]<<" ";
cout<<map[i][j]<<endl;
}
caseid++;
}
return 0;
}
测试case:
7 0 1 0 2 0 4 2 4 2 3 3 1 4 35 0 2 0 1 1 5 2 5 2 190 1 0 2 0 30 4 1 4 2 12 03 03 1输出结果:
matrix for city 00 4 1 3 20 0 0 0 00 2 0 2 10 1 0 0 00 1 0 1 0matrix for city 10 2 1 0 0 30 0 0 0 0 10 1 0 0 0 20 0 0 0 0 00 0 0 0 0 00 0 0 0 0 0matrix for city 2-1 -1 -1 -1 -10 0 0 0 1-1 -1 -1 -1 -1-1 -1 -1 -1 -10 0 0 0 0
- 125 - Numbering Paths 解题报告
- uva 125 - Numbering Paths
- 125 - Numbering Paths
- UVA - 125 Numbering Paths
- UVA 125 Numbering Paths
- uva 125Numbering Paths
- USACO :Preface Numbering 解题报告
- UVA 125 - Numbering Paths(floyd)
- UVa 125 Numbering Paths / floyd
- UVA - 125 Numbering Paths floyd的变形
- Numbering Paths - UVa 125 Floyd求环
- uva 125 Numbering Paths(warshall算法)
- Numbering Paths (Uva 125 floyd+dp思想)
- UVa 125 Numbering Paths (路径统计+Floyd)
- 【LeetCode】Unique Paths 解题报告
- [LeetCode] Unique Paths 解题报告
- HDU-1625-Numbering Paths
- UVa125 - Numbering Paths
- Android 四大组件学习之activity的四种加载模式介绍
- Java中如何向系统剪贴板写入富文本
- Android软件开发之ListView 详解
- 吉哥系列故事——完美队形
- hdu 1143 递推
- 125 - Numbering Paths 解题报告
- 一个关于memset使用的问题
- HLA时间管理机制
- cocos2d-x 中CCLayer runAction没有效果 原因
- 计算机网络的五层工作流程
- [vim]vim中复制粘贴
- 提高oracle海量数据写入效率
- Shell 脚本 遍历文件夹
- SSH框架