Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.93 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <cstdio>
  7. #include <random>
  8. #include <ctime>
  9. #include <string>
  10. #include <iomanip>
  11. #include <set>
  12. #include <map>
  13. #include <queue>
  14. #include <stack>
  15.  
  16. using namespace std;
  17.  
  18. typedef long long li;
  19. typedef unsigned long long uli;
  20. typedef pair<int, int> pii;
  21. typedef long double ld;
  22.  
  23. #define all(a) a.begin(), a.end()
  24. #define rall(a) a.rbegin(), a.rend()
  25. #define fr first
  26. #define sc second
  27. #define pb push_back
  28. #define forn(i, n) for(int i = 0; i < int(n); ++i)
  29. #define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
  30. #define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)
  31. #define vi vector<int>
  32. //#define x first
  33. //#define y second
  34.  
  35. const int INF = 2e9;
  36. const li INF64 = 4e18;
  37. const int M = 27;
  38. const int N = 5;
  39. const int MOD = 1e9 + 7;
  40. const double EPS = 1e-9;
  41. const double PI = 3.14159265359;
  42. li gcd(li a, li b) {
  43.     return (b == 0 ? a : gcd(b, a % b));
  44. }
  45.  
  46. int main() {
  47. //#ifdef _DEBUG
  48.     //freopen("input.txt", "r", stdin);
  49.     //freopen("output.txt", "w", stdout);
  50. //#endif
  51.     ios_base::sync_with_stdio(0);
  52.     cin.tie(0);
  53.  
  54.     int n;
  55.     cin >> n;
  56.  
  57.     vector<vector<char>> t(n - 2, vector<char>(n - 2));
  58.  
  59.     //обработка имеющегося тайла
  60.     forn(i, n) {
  61.         string s;
  62.         cin >> s;
  63.         if (i != 0 && i != n - 1) {
  64.             for (int j = 1; j < s.size() - 1; ++j)
  65.                 t[i - 1][j - 1] = s[j];
  66.         }
  67.     }
  68.  
  69.     set <vector<vector<char>>> ts;
  70.  
  71.     ts.insert(t);
  72.  
  73.     //исключительные повороты тайла
  74.     forn(x, 3) {
  75.         vector<vector<char>> nw(n - 2, vector<char>(n - 2));
  76.  
  77.         forn(i, n - 2)
  78.             forn(j, n - 2)
  79.             nw[i][j] = t[j][n - 2 - 1 - i];
  80.  
  81.         t = nw;
  82.         ts.insert(t);
  83.     }
  84.  
  85.     int h, w;
  86.     cin >> h >> w;
  87.     int hn = h / (n - 1);
  88.     int wn = w / (n - 1);
  89.  
  90.     //привели поле к нормальному виду
  91.     vector<vector<char>> p(hn * (n - 2) + (n - 2) * 2);
  92.     forn(i, wn * (n - 2) + (n - 2) * 2) {
  93.         forn(j, n - 2) {
  94.             p[j].pb('.');
  95.             p[p.size() - 1 - j].pb('.');
  96.         }
  97.     }
  98.     int ih = n - 2;
  99.     forn(i, n - 2) p[ih].pb('.');
  100.     forn(i, h) {
  101.         forn(j, w) {
  102.             char t;
  103.             cin >> t;
  104.             if (i % (n - 1) != 0 && j % (n - 1) != 0) {
  105.                 p[ih].pb(t);
  106.             }
  107.         }
  108.         if (i % (n - 1) != 0) {
  109.             forn(q, n - 2) p[ih].pb('.');
  110.             ih++;
  111.             if (ih != p.size() - (n - 2)) forn(q, n - 2) p[ih].pb('.');
  112.         }
  113.     }
  114.  
  115.     forn(i, hn * (n - 2) + (n - 2) * 2) {
  116.         forn(j, p[i].size())
  117.             cout << p[i][j];
  118.         cout << endl;
  119.     }
  120.    
  121.     int ans = 0;
  122.  
  123.     //пытаемся подставлять тайлы на место точек
  124.     for (int i = 0; i < hn * (n - 2) + (n - 2) * 2; i += (n - 2)) {
  125.         for (int j = 0; j < wn * (n - 2) + (n - 2) * 2; j += (n - 2)) {
  126.             if (p[i][j] == '.') {  //появилось место под тайл
  127.                 for (auto cur : ts) {
  128.                     bool bor = false; //количество непустых границ
  129.                     bool ok = true; //все совпадает
  130.                     cout << i << " " << j << " ";
  131.                     if (i != 0) { //сверяем с верхней
  132.                         forn(x, n - 2) {
  133.                             if (p[i - 1][x] != cur[0][x] && p[i - 1][x] != '.') ok = false;
  134.                             if (p[i - 1][x] != '.') bor = true;
  135.                         }
  136.                     }
  137.                     cout << "up ";
  138.                     if (j != 0) { //сверяем с левой
  139.                         forn(x, n - 2) {
  140.                             if (p[x][j - 1] != cur[x][0] && p[x][j - 1] != '.') ok = false;
  141.                             if (p[x][j - 1] != '.') bor = true;
  142.                         }
  143.                     }
  144.                     cout << "left ";
  145.                     if (i + (n - 2) < p.size()) { //сверяем с нижней
  146.                         forn(x, n - 2) {
  147.                             if (p[i + (n - 2)][j + x] != cur[n - 1][x] && p[i + (n - 2)][j + x] != '.') ok = false;
  148.                             if (p[i + (n - 2)][j + x] != '.') bor = true;
  149.                         }
  150.                     }
  151.                     cout << "down ";
  152.                     if (j + (n - 2) < p[0].size()) { //сверяем с правой
  153.                         forn(x, n - 2) {
  154.                             if (p[x][j + (n - 2)] != cur[x][n - 1] && p[x][j + (n - 2)] != '.') ok = false;
  155.                             if (p[x][j + (n - 2)] != '.') bor = true;
  156.                         }
  157.                     }
  158.                     cout << "right\n";
  159.                     if (ok && bor) ans++;
  160.                 }
  161.             }
  162.         }
  163.     }
  164.  
  165.     cout << ans;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement