您的位置:首页 > 编程语言 > C语言/C++

[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 Link

Analysis:

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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: