Advertisement
supremeXD

Untitled

Oct 11th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. using namespace std;
  6.  
  7. bool imp(bool a, bool b) { // импликация
  8. return !(a == 1 && b == 0);
  9. }
  10.  
  11. bool isAntisim(vector<pair<int,int>>&a) {
  12. for(int i = 0; i < a.size(); i++) {
  13. for(int j = i + 1; j < a.size(); j++) {
  14. if(!imp(a[i].first == a[j].second && a[i].second == a[j].first, a[i] == a[j])) {
  15. return false;
  16. }
  17. }
  18. }
  19. return true;
  20. }
  21.  
  22. bool isRefl(vector<pair<int,int>>&a, int n) {
  23. set<int>mySet;
  24. for(auto & i : a) {
  25. if(i.first == i.second) {
  26. mySet.insert(i.first);
  27. }
  28. }
  29. return (mySet.size() == n);
  30. }
  31.  
  32. bool isAntirefl(vector<pair<int,int>>&a) {
  33. for(auto & i : a) {
  34. if(i.first == i.second) {
  35. return false;
  36. }
  37. }
  38. return true;
  39. }
  40.  
  41. bool isSim(vector<pair<int,int>>&a) {
  42. for(int i = 0; i < a.size(); i++) {
  43. bool found = false;
  44. for(int j = 0; j < a.size(); j++) {
  45. if(a[i].first == a[j].second && a[i].second == a[j].first) {
  46. found = true;
  47. break;
  48. }
  49. }
  50. if(!found) {
  51. return false;
  52. }
  53. }
  54. return true;
  55. }
  56.  
  57. bool isTranz(vector<pair<int,int>>&a) {
  58. for(int i = 0; i < a.size(); i++) {
  59. for(int j = 0; j < a.size(); j++) {
  60. if(i == j) continue;
  61. for(int h = 0; h < a.size(); h++) {
  62. if(h == j || h == i) continue;
  63. if(!imp(a[i].second == a[j].first, a[i].first == a[h].first && a[h].second == a[j].first)) {
  64. return false;
  65. }
  66. }
  67. }
  68. }
  69. return true;
  70. }
  71.  
  72. vector<vector<int>>comp(vector<pair<int,int>>&a, vector<pair<int,int>>&b, int n) {
  73. vector<vector<int>>to_return(n, vector<int>(n));
  74. for(int i = 0; i < a.size(); i++) {
  75. for(int j = 0; j < b.size(); j++) {
  76. if(a[i].second == b[j].first) {
  77. to_return[a[i].first][b[j].second] = 1;
  78. }
  79. }
  80. }
  81. return to_return;
  82. }
  83.  
  84. int main() {
  85. int n; cin >> n; // всего n элементов
  86. vector<pair<int,int>>f;
  87. vector<pair<int,int>>s;
  88. for(int i = 0; i < n; i++) {
  89. for(int j = 0; j < n; j++) {
  90. int val; cin >> val;
  91. if(val == 1) {
  92. f.emplace_back(i, j);
  93. }
  94. }
  95. }
  96. for(int i = 0; i < n; i++) {
  97. for(int j = 0; j < n; j++) {
  98. int val; cin >> val;
  99. if(val == 1) {
  100. s.emplace_back(i, j);
  101. }
  102. }
  103. }
  104.  
  105. cout << isRefl(f, n) << " " << isAntirefl(f) << " " << isSim(f) << " " << isAntisim(f) << " " << isTranz(f) << endl;
  106. cout << isRefl(s, n) << " " << isAntirefl(s) << " " << isSim(s) << " " << isAntisim(s) << " " << isTranz(s) << endl;
  107.  
  108. vector<vector<int>>c = comp(f, s, n);
  109. for(int i = 0; i < c.size(); i++) {
  110. for(int j = 0; j < c[i].size(); j++) {
  111. cout << c[i][j] << " ";
  112. }
  113. cout << endl;
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement