[C++]Operation on Relations
2016-04-23 12:15
375 查看
Operation on Relations
Description:
This problem tries to put discrete mathematical structure in program. Using matrix, set to show relation. It is a bit hard but not severely difficult.The demo link:
Demo LinkAnalysis:
The answer, given by TA, is much easier than me. He use many method which has been given before, even if that method is also easy to write again, but it still save much time and decrese errors. It is a good tip whatever.BinaryRelation BinaryRelation::transitiveClosure() const { int n = matrix.getRow(); BooleanMatrix temp(matrix); for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { temp.replace(temp.getElement(i, j) | (temp.getElement(i, k) & temp.getElement(k, j)), i, j); } } } return BinaryRelation(temp, set); }
相关文章推荐
- C++ for循环跳过某一项求和
- freopen-C/C++方便的文件输入输出
- C/C++学习笔记(2)--函数模板template<typename T>,类模板详解(1)
- [C++]Stack with Template
- C++ 效率
- c语言.野指针
- C++ string 常用函数/方法
- JAVA使用JNI调用C++动态链接库
- S3C2440之UART0
- VC++深入详解第一章代码
- Notepad++插件:文件目录,自动补全,显示类,命令行
- 用实例讲解栈和队列(C++)
- c语言:输入一行字符,统计其中的单词个数,单词之间用空格分开
- Leetcode 9. Palindrome Number
- C++中vector内存泄露问题
- C语言中的隐式转换
- C语言中不同类型的指针互相转换的注意点
- c++实现二叉树(递归)
- c++ 读书目录
- C语言基础及数据类型