Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- bool sh = 1;
- void cvch(vector <vector <char> > a) {
- for (auto v: a) {
- for (auto i: v) {
- cout << i;
- } cout << "\n";
- } cout << "\n";
- }
- int n, m, inf = 2e9;
- struct rct {
- int x1, x2, y1, y2;
- void upd(int i, int j, int n, int m) {
- int yi = n - 1 - i;
- int xj = j;
- if (sh) {
- //cout << "i j = " << i << ' ' << j << "\n";
- //cout << "yi xj = " << yi << ' ' << xj << "\n";
- }
- x1 = min(x1, xj);
- x2 = max(x2, xj);
- y1 = min(y1, yi);
- y2 = max(y2, yi);
- }
- void see() {
- cout << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << "\n";
- }
- };
- rct getrec(vector <vector <int> > a) {
- rct res = {inf, -1, inf, -1};
- if (sh) {
- cout << "GETREC\n";
- }
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (a[i][j] == 0) {
- res.upd(i, j, n, n);
- }
- }
- if (sh) {
- //cout << "I = " << i << "\n";
- //cout << "res\n";
- //res.see();
- //cout << "\n";
- }
- }
- return res;
- }
- bool in(rct rec, int i, int j) {
- int xj = j;
- int yi = m - 1 - i;
- return xj >= rec.x1
- && xj <= rec.x2
- && yi >= rec.y1
- && yi <= rec.y2;
- }
- bool noout(vector <vector <int> > a, int clr, rct rec) {
- //n m global ok???
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < m; ++j) {
- if (a[i][j] == clr) {
- if (!in(rec, i, j)) {
- return 0;
- }
- }
- }
- }
- return 1;
- }
- bool gen = 0;
- vector <vector <int> > mtr;
- void getmtr(vector <vector <int> > a) {
- rct rec = getrec(a);
- if (sh) {
- cout << "rec\n";
- rec.see();
- }
- int lx = rec.x2 - rec.x1 + 1;
- int ly = rec.y2 - rec.y1 + 1;
- mtr.resize(ly, vector <int> (lx, 99));
- int fri = n - rec.y2;
- int toi = fri + ly - 1;
- fri--;
- toi--;
- int frj = rec.x1;
- int toj = rec.x2;
- if (sh) {
- cout << "fri toi = " << fri << ' ' << toi << "\n";
- cout << "frj toj = " << frj << ' ' << toj << "\n";
- }
- int x = -1;
- for (int i = fri; i <= toi; ++i) {
- x++;
- int y = -1;
- for (int j = frj; j <= toj; ++j) {
- y++;
- mtr[x][y] = a[i][j];
- }
- }
- n = ly;
- m = lx;
- //new, n m for needed matrix
- }
- /*
- 13
- .............
- .............
- .............
- ..#######....
- ..#######....
- ..###........
- ..###........
- ..###........
- ..###........
- ..#######....
- ..#######....
- .............
- .............
- */
- bool Csee = 0;
- bool Hsee = 0;
- /*
- 10
- ..........
- ..##...#..
- ..##...#..
- ..##...#..
- ..##...#..
- ..######..
- ..##...#..
- ..##...#..
- ..........
- ..........
- 10
- ..........
- ..##...#..
- ..##...#..
- ..##...#..
- ..##...#..
- ..######..
- ..##...#..
- ..##...#..
- ..........
- .........#
- */
- int main() {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- //cin >> n;
- //m = n;
- if (Csee) {
- vector <vector <char> > raw(13, vector <char> (13, '.'));
- for (int i = 3; i <= 4; ++i) {
- for (int j = 2; j <= 8; ++j) {
- raw[i][j] = '#';
- }
- }
- for (int i = 5; i <= 8; ++i) {
- for (int j = 2; j <= 4; ++j) {
- raw[i][j] = '#';
- }
- }
- for (int i = 9; i <= 10; ++i) {
- for (int j = 2; j <= 8; ++j) {
- raw[i][j] = '#';
- }
- }
- cvch(raw);
- }
- if (Hsee) {
- vector <vector <char> > raw(10, vector <char> (10, '.'));
- for (int i = 1; i <= 7; ++i) {
- for (int j = 2; j <= 3; ++j) {
- raw[i][j] = '#';
- }
- raw[i][7] = '#';
- }
- for (int j = 2; j <= 7; ++j) {
- raw[5][j] = '#';
- }
- cvch(raw);
- }
- cin >> n;
- m = n;
- vector <vector <int> > a(n, vector <int> (n, 99));
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- char k;
- cin >> k;
- if (k == '#') {
- a[i][j] = 0;
- } else {
- a[i][j] = 1;
- }
- }
- }
- getmtr(a);
- if (sh) {
- cout << "mtr\n";
- cvv(mtr);
- }
- }
- /*
- 13
- .............
- .............
- .............
- ..#######....
- ..#######....
- ..###........
- ..###........
- ..###........
- ..###........
- ..#######....
- ..#######....
- .............
- .............
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement