Advertisement
Korotkodul

N5 3

Oct 25th, 2022 (edited)
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.49 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.  
  137.     mtr.resize(ly, vector <int> (lx, 99));
  138.     int fri = n - rec.y2;
  139.     int toi = fri + ly - 1;
  140.     fri--;
  141.     toi--;
  142.     int frj = rec.x1;
  143.     int toj = rec.x2;
  144.  
  145.     if (sh) {
  146.         cout << "fri toi = " << fri << ' ' << toi << "\n";
  147.         cout << "frj toj = " << frj << ' ' << toj << "\n";
  148.     }
  149.  
  150.     int x = -1;
  151.     for (int i = fri; i <= toi; ++i) {
  152.         x++;
  153.         int y = -1;
  154.         for (int j = frj; j <= toj; ++j) {
  155.             y++;
  156.             mtr[x][y] = a[i][j];
  157.         }
  158.     }
  159.     n = ly;
  160.     m = lx;
  161.     //new, n m for needed matrix
  162. }
  163.  
  164.  
  165. /*
  166. 13
  167. .............
  168. .............
  169. .............
  170. ..#######....
  171. ..#######....
  172. ..###........
  173. ..###........
  174. ..###........
  175. ..###........
  176. ..#######....
  177. ..#######....
  178. .............
  179. .............
  180. */
  181.  
  182. bool Csee = 0;
  183. bool Hsee = 0;
  184. /*
  185. 10
  186. ..........
  187. ..##...#..
  188. ..##...#..
  189. ..##...#..
  190. ..##...#..
  191. ..######..
  192. ..##...#..
  193. ..##...#..
  194. ..........
  195. ..........
  196.  
  197. 10
  198. ..........
  199. ..##...#..
  200. ..##...#..
  201. ..##...#..
  202. ..##...#..
  203. ..######..
  204. ..##...#..
  205. ..##...#..
  206. ..........
  207. .........#
  208. */
  209.  
  210. int main() {
  211.     /*ios::sync_with_stdio(0);
  212.     cin.tie(0);
  213.     cout.tie(0);*/
  214.     //cin >> n;
  215.     //m = n;
  216.     if (Csee) {
  217.         vector <vector <char> > raw(13, vector <char> (13, '.'));
  218.         for (int i = 3; i <= 4; ++i) {
  219.             for (int j = 2; j <= 8; ++j) {
  220.                 raw[i][j] = '#';
  221.             }
  222.         }
  223.         for (int i = 5; i <= 8; ++i) {
  224.             for (int j = 2; j <= 4; ++j) {
  225.                 raw[i][j] = '#';
  226.             }
  227.         }
  228.         for (int i = 9; i <= 10; ++i) {
  229.             for (int j = 2; j <= 8; ++j) {
  230.                 raw[i][j] = '#';
  231.             }
  232.         }
  233.         cvch(raw);
  234.     }
  235.     if (Hsee) {
  236.         vector <vector <char> > raw(10, vector <char> (10, '.'));
  237.         for (int i = 1; i <= 7; ++i) {
  238.             for (int j = 2; j <= 3; ++j) {
  239.                 raw[i][j] = '#';
  240.             }
  241.             raw[i][7] = '#';
  242.         }
  243.         for (int j = 2; j <= 7; ++j) {
  244.             raw[5][j] = '#';
  245.         }
  246.         cvch(raw);
  247.     }
  248.  
  249.     cin >> n;
  250.     m = n;
  251.     vector <vector <int> > a(n, vector <int> (n, 99));
  252.     for (int i = 0; i < n; ++i) {
  253.         for (int j = 0; j < n; ++j) {
  254.             char k;
  255.             cin >> k;
  256.             if (k == '#') {
  257.                 a[i][j] = 0;
  258.             } else {
  259.                 a[i][j] = 1;
  260.             }
  261.         }
  262.     }
  263.     getmtr(a);
  264.     if (sh) {
  265.         cout << "mtr\n";
  266.         cvv(mtr);
  267.     }
  268. }
  269.  
  270. /*
  271. 13
  272. .............
  273. .............
  274. .............
  275. ..#######....
  276. ..#######....
  277. ..###........
  278. ..###........
  279. ..###........
  280. ..###........
  281. ..#######....
  282. ..#######....
  283. .............
  284. .............
  285. */
  286.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement