Advertisement
Georgiy1108

Untitled

Sep 20th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<pair<int, int>> v{{0, 0}, {1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}};
  6.  
  7. bool operator!=(pair<int, int> a, pair<int, int> b)
  8. {
  9.     return (a.first != b.first && a.second != b.second);
  10. }
  11.  
  12. bool f(pair<int, int> a, pair<int, int> b, pair<int, int> c)
  13. {
  14.     set<int> s1, s2;
  15.     s1.insert(a.first);
  16.     s1.insert(b.first);
  17.     s1.insert(c.first);
  18.     s2.insert(a.second);
  19.     s2.insert(b.second);
  20.     s2.insert(c.second);
  21.     return ((s1.size() == 3 && s2.size() == 1) || (s2.size() == 3 && s1.size() == 1) || (s2.size() == 3 && s1.size() == 3)
  22.     || (s1.size() == 1 && s2.size() == 1));
  23. }
  24.  
  25. check(vector<vector<set<int>>> &m)
  26. {
  27.     for(int i = 1; i <= 9; i++)
  28.     {
  29.         if(m[v[i].first][v[i].second].size() == 0)
  30.             continue;
  31.         for(int j = 1; j <= 9; j++)
  32.         {
  33.             if(m[v[j].first][v[j].second].size() == 0)
  34.                 continue;
  35.             if(i == j && m[v[j].first][v[j].second].size() < 2)
  36.                 continue;
  37.             for(int k = 1; k <= 9; k++)
  38.             {
  39.                 if(m[v[k].first][v[k].second].size() == 0)
  40.                     continue;
  41.                 if(k == j && m[v[k].first][v[k].second].size() < 2)
  42.                     continue;
  43.                 if(k == j && j == i && m[v[k].first][v[k].second].size() < 3)
  44.                     continue;
  45.                 if(f(v[i], v[j], v[k]))
  46.                 {
  47.                     int i1 = *m[v[i].first][v[i].second].begin();
  48.                     m[v[i].first][v[i].second].erase(*m[v[i].first][v[i].second].begin());
  49.                     int i2 = *m[v[j].first][v[j].second].begin();
  50.                     m[v[j].first][v[j].second].erase(*m[v[j].first][v[j].second].begin());
  51.                     int i3 = *m[v[k].first][v[k].second].begin();
  52.                     m[v[k].first][v[k].second].erase(*m[v[k].first][v[k].second].begin());
  53.                     cout << i1 << " " << i2 << " " << i3 << "\n";
  54.                 }
  55.             }
  56.         }
  57.     }
  58. }
  59.  
  60. main()
  61. {
  62.     vector<vector<set<int>>> m(4, vector<set<int>>(4, set<int>()));
  63.     int n;
  64.     cin >> n;
  65.     for(int i = 0; i < n; i++)
  66.     {
  67.         int f, t;
  68.         cin >> f >> t;
  69.         m[f][t].insert(i + 1);
  70.         check(m);
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement