SDUT 3812 离散题目18
来源:互联网 发布:淘宝奥特曼星计划 编辑:程序博客网 时间:2024/06/16 21:23
Problem Description
给出一个集合A和A上的关系R,求关系R的传递闭包。
例如:
A={0,1,2} , R={<0,0>,<1,0>,<2,2>,<1,2>,<2,1>}
t(R) = {<0,0>,<1,0>,<2,2>,<2,1>,<1,2>,<1,1>,<2,0>};
Input
多组输入,输入n、m,集合A={0, 1, …, n-1 };m代表关系的数量,n、m不超过20.
Output
每组输入输出t(R),根据t(R)中序偶的第一个数字升序排序,如果第一个数字相同,根据第二个升序排序。
Example Input
3 5
0 0
1 0
2 2
1 2
2 1
Example Output
0 0
1 0
1 1
1 2
2 0
2 1
2 2
代码:求传递闭包warshall算法
#include<bits/stdc++.h>using namespace std;int Map[200][200];int main(){ int n, m, u, v, i, j, k; while(~scanf("%d %d", &n, &m)) { memset(Map, 0, sizeof(Map)); while(m--) { scanf("%d %d", &u, &v); Map[u][v] = 1; } for(i = 0; i < n; i++)//第i列 warshall算法 { for(j = 0; j < n; j++)//第j行 { if(Map[j][i]) { for(k = 0; k < n; k++)//第i行加到第j行上 { Map[j][k] += Map[i][k]; } } } } for(i = 0; i < n; i++)//输出 { for(j = 0; j < n; j++) { if(Map[i][j]) printf("%d %d\n", i, j); } } } return 0;}
阅读全文
0 0
- SDUT 3812 离散题目18
- sdut-离散题目18
- sdut离散题目11
- sdut离散题目13
- sdut离散题目14
- SDUT-离散题目13
- SDUT-离散题目7
- SDUT离散题目4
- sdut-离散题目3
- sdut- 离散题目4
- sdut-离散题目5
- sdut-离散题目6
- sdut-离散题目7
- sdut-离散题目8
- sdut-离散题目9
- sdut-离散题目10
- sdut-离散题目11
- sdut-离散题目12
- Next Permutation
- 算法—猜拳游戏
- (原创)HyperPacer使用技巧之集合点设置
- 微信公众号开发--微信JS-SDK扫一扫功能
- 阿里云centos修改ssh端口后连接失败
- SDUT 3812 离散题目18
- iOS开发
- webservice注解
- python计算文件夹大小(linux du命令 简化版)
- 1.什么是缓存
- sklearn分类算法测试以及自动化调参
- 【微小说】理想
- 下载安装APK(兼容Android7.0)
- 关于Win7固态优盘的优化方法