Advertisement
Korotkodul

N5 2

Oct 25th, 2022 (edited)
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. bool sh = 1;
  51.  
  52. void cvch(vector <vector <char> > a) {
  53.     for (auto v: a) {
  54.         for (auto i: v) {
  55.             cout << i;
  56.         } cout << "\n";
  57.     } cout << "\n";
  58. }
  59.  
  60. int n, m, inf = 2e9;
  61.  
  62. struct rct {
  63.     int x1, x2, y1, y2;
  64.     void upd(int i, int j, int n, int m) {
  65.         int yi = n - 1 - i;
  66.         int xj = j;
  67.         if (sh) {
  68.             //cout << "i j = " << i << ' ' << j << "\n";
  69.             //cout << "yi xj = " << yi << ' ' << xj << "\n";
  70.         }
  71.         x1 = min(x1, xj);
  72.         x2 = max(x2, xj);
  73.         y1 = min(y1, yi);
  74.         y2 = max(y2, yi);
  75.     }
  76.  
  77.     void see() {
  78.         cout << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << "\n";
  79.     }
  80. };
  81.  
  82. rct getrec(vector <vector <int> > a) {
  83.     rct res = {inf, -1, inf, -1};
  84.     if (sh) {
  85.         cout << "GETREC\n";
  86.     }
  87.     for (int i = 0; i < n; ++i) {
  88.         for (int j = 0; j < n; ++j) {
  89.             if (a[i][j] == 0) {
  90.                 res.upd(i, j, n, n);
  91.             }
  92.         }
  93.         if (sh) {
  94.             //cout << "I = " << i << "\n";
  95.             //cout << "res\n";
  96.             //res.see();
  97.             //cout << "\n";
  98.         }
  99.     }
  100.     return res;
  101. }
  102.  
  103. bool in(rct rec, int i, int j) {
  104.     int xj = j;
  105.     int yi = m - 1 - i;
  106.     return xj >= rec.x1
  107.     && xj <= rec.x2
  108.     && yi >= rec.y1
  109.     && yi <= rec.y2;
  110. }
  111.  
  112. bool noout(vector <vector <int> > a, int clr, rct rec) {
  113.     //n m global ok???
  114.     for (int i = 0; i < n; ++i) {
  115.         for (int j = 0; j < m; ++j) {
  116.             if (a[i][j] == clr) {
  117.                 if (!in(rec, i, j)) {
  118.                     return 0;
  119.                 }
  120.             }
  121.         }
  122.     }
  123.     return 1;
  124. }
  125. bool gen = 0;
  126. vector <vector <int> > mtr;
  127.  
  128. void getmtr(vector <vector <int> > a) {
  129.     rct rec = getrec(a);
  130.     if (sh) {
  131.         cout << "rec\n";
  132.         rec.see();
  133.     }
  134.     /*int lx = rec.x2 - rec.x1 + 1;
  135.     int ly = rec.y2 - rec.y1 + 1;
  136.     n = lx;
  137.     m = ly;
  138.     mtr.resize(n, vector <int> (m, 99));
  139.     int fri = n - rec.y2;
  140.     int toi = fri + ly - 1;
  141.     int frj = rec.x1;
  142.     int toj = rec.x2;
  143.     int x = -1;
  144.     for (int i = fri; i <= toi; ++i) {
  145.         x++;
  146.         int y = -1;
  147.         for (int j = frj; j <= toj; ++j) {
  148.             y++;
  149.             mtr[x][y] = a[i][j];
  150.         }
  151.     }*/
  152. }
  153.  
  154.  
  155. /*
  156. 13
  157. .............
  158. .............
  159. .............
  160. ..#######....
  161. ..#######....
  162. ..###........
  163. ..###........
  164. ..###........
  165. ..###........
  166. ..#######....
  167. ..#######....
  168. .............
  169. .............
  170. */
  171.  
  172.  
  173. int main() {
  174.     /*ios::sync_with_stdio(0);
  175.     cin.tie(0);
  176.     cout.tie(0);*/
  177.     //cin >> n;
  178.     //m = n;
  179.     if (gen) {
  180.         vector <vector <char> > raw(13, vector <char> (13, '.'));
  181.         for (int i = 3; i <= 4; ++i) {
  182.             for (int j = 2; j <= 8; ++j) {
  183.                 raw[i][j] = '#';
  184.             }
  185.         }
  186.         for (int i = 5; i <= 8; ++i) {
  187.             for (int j = 2; j <= 4; ++j) {
  188.                 raw[i][j] = '#';
  189.             }
  190.         }
  191.         for (int i = 9; i <= 10; ++i) {
  192.             for (int j = 2; j <= 8; ++j) {
  193.                 raw[i][j] = '#';
  194.             }
  195.         }
  196.         cvch(raw);
  197.     }
  198.  
  199.     cin >> n;
  200.     m = n;
  201.     vector <vector <int> > a(n, vector <int> (n, 99));
  202.     for (int i = 0; i < n; ++i) {
  203.         for (int j = 0; j < n; ++j) {
  204.             char k;
  205.             cin >> k;
  206.             if (k == '#') {
  207.                 a[i][j] = 0;
  208.             } else {
  209.                 a[i][j] = 1;
  210.             }
  211.         }
  212.     }
  213.     getmtr(a);
  214.     if (sh) {
  215.         cout << "mtr\n";
  216.         cvv(mtr);
  217.     }
  218. }
  219.  
  220. /*
  221. 13
  222. .............
  223. .............
  224. .............
  225. ..#######....
  226. ..#######....
  227. ..###........
  228. ..###........
  229. ..###........
  230. ..###........
  231. ..#######....
  232. ..#######....
  233. .............
  234. .............
  235. */
  236.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement