Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <set>
- using namespace std;
- bool imp(bool a, bool b) { // импликация
- return !(a == 1 && b == 0);
- }
- bool isAntisim(vector<pair<int,int>>&a) {
- for(int i = 0; i < a.size(); i++) {
- for(int j = i + 1; j < a.size(); j++) {
- if(!imp(a[i].first == a[j].second && a[i].second == a[j].first, a[i] == a[j])) {
- return false;
- }
- }
- }
- return true;
- }
- bool isRefl(vector<pair<int,int>>&a, int n) {
- set<int>mySet;
- for(auto & i : a) {
- if(i.first == i.second) {
- mySet.insert(i.first);
- }
- }
- return (mySet.size() == n);
- }
- bool isAntirefl(vector<pair<int,int>>&a) {
- for(auto & i : a) {
- if(i.first == i.second) {
- return false;
- }
- }
- return true;
- }
- bool isSim(vector<pair<int,int>>&a) {
- set<pair<int,int>>mySet;
- for(int i = 0; i < a.size(); i++) {
- mySet.insert(a[i]);
- }
- for(int i = 0; i < a.size(); i++) {
- if(mySet.find({a[i].second,a[i].first}) == mySet.end()) {
- return false;
- }
- }
- return true;
- }
- bool isTranz(vector<pair<int,int>>&a) {
- for(int i = 0; i < a.size(); i++) {
- for(int j = 0; j < a.size(); j++) {
- if(i == j) continue;
- for(int h = 0; h < a.size(); h++) {
- if(h == j || h == i) continue;
- if(!imp(a[i].second == a[j].first, a[i].first == a[h].first && a[h].second == a[j].first)) {
- return false;
- }
- }
- }
- }
- return true;
- }
- vector<vector<int>>comp(vector<pair<int,int>>&a, vector<pair<int,int>>&b, int n) {
- vector<vector<int>>to_return(n, vector<int>(n));
- for(int i = 0; i < a.size(); i++) {
- for(int j = 0; j < b.size(); j++) {
- if(a[i].second == b[j].first) {
- to_return[a[i].first][b[j].second] = 1;
- }
- }
- }
- return to_return;
- }
- int main() {
- int n; cin >> n; // всего n элементов
- vector<pair<int,int>>f;
- vector<pair<int,int>>s;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- int val; cin >> val;
- if(val == 1) {
- f.emplace_back(i, j);
- }
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- int val; cin >> val;
- if(val == 1) {
- s.emplace_back(i, j);
- }
- }
- }
- cout << isRefl(f, n) << " " << isAntirefl(f) << " " << isSim(f) << " " << isAntisim(f) << " " << isTranz(f) << endl;
- cout << isRefl(s, n) << " " << isAntirefl(s) << " " << isSim(s) << " " << isAntisim(s) << " " << isTranz(s) << endl;
- vector<vector<int>>c = comp(f, s, n);
- for(int i = 0; i < c.size(); i++) {
- for(int j = 0; j < c[i].size(); j++) {
- cout << c[i][j] << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement