Advertisement
supremeXD

Untitled

Oct 11th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 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. set<pair<int,int>>mySet;
  43. for(int i = 0; i < a.size(); i++) {
  44. mySet.insert(a[i]);
  45. }
  46. for(int i = 0; i < a.size(); i++) {
  47. if(mySet.find({a[i].second,a[i].first}) == mySet.end()) {
  48. return false;
  49. }
  50. }
  51. return true;
  52. }
  53.  
  54. bool isTranz(vector<pair<int,int>>&a) {
  55. for(int i = 0; i < a.size(); i++) {
  56. for(int j = 0; j < a.size(); j++) {
  57. if(i == j) continue;
  58. for(int h = 0; h < a.size(); h++) {
  59. if(h == j || h == i) continue;
  60. if(!imp(a[i].second == a[j].first, a[i].first == a[h].first && a[h].second == a[j].first)) {
  61. return false;
  62. }
  63. }
  64. }
  65. }
  66. return true;
  67. }
  68.  
  69. vector<vector<int>>comp(vector<pair<int,int>>&a, vector<pair<int,int>>&b, int n) {
  70. vector<vector<int>>to_return(n, vector<int>(n));
  71. for(int i = 0; i < a.size(); i++) {
  72. for(int j = 0; j < b.size(); j++) {
  73. if(a[i].second == b[j].first) {
  74. to_return[a[i].first][b[j].second] = 1;
  75. }
  76. }
  77. }
  78. return to_return;
  79. }
  80.  
  81. int main() {
  82. int n; cin >> n; // всего n элементов
  83. vector<pair<int,int>>f;
  84. vector<pair<int,int>>s;
  85. for(int i = 0; i < n; i++) {
  86. for(int j = 0; j < n; j++) {
  87. int val; cin >> val;
  88. if(val == 1) {
  89. f.emplace_back(i, j);
  90. }
  91. }
  92. }
  93. for(int i = 0; i < n; i++) {
  94. for(int j = 0; j < n; j++) {
  95. int val; cin >> val;
  96. if(val == 1) {
  97. s.emplace_back(i, j);
  98. }
  99. }
  100. }
  101.  
  102. cout << isRefl(f, n) << " " << isAntirefl(f) << " " << isSim(f) << " " << isAntisim(f) << " " << isTranz(f) << endl;
  103. cout << isRefl(s, n) << " " << isAntirefl(s) << " " << isSim(s) << " " << isAntisim(s) << " " << isTranz(s) << endl;
  104.  
  105. vector<vector<int>>c = comp(f, s, n);
  106. for(int i = 0; i < c.size(); i++) {
  107. for(int j = 0; j < c[i].size(); j++) {
  108. cout << c[i][j] << " ";
  109. }
  110. cout << endl;
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement