Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cstdio>
- #include <random>
- #include <ctime>
- #include <string>
- #include <iomanip>
- #include <set>
- #include <map>
- #include <queue>
- #include <stack>
- using namespace std;
- typedef long long li;
- typedef unsigned long long uli;
- typedef pair<int, int> pii;
- typedef long double ld;
- #define all(a) a.begin(), a.end()
- #define rall(a) a.rbegin(), a.rend()
- #define fr first
- #define sc second
- #define pb push_back
- #define forn(i, n) for(int i = 0; i < int(n); ++i)
- #define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
- #define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)
- #define vi vector<int>
- //#define x first
- //#define y second
- const int INF = 2e9;
- const li INF64 = 4e18;
- const int M = 27;
- const int N = 5;
- const int MOD = 1e9 + 7;
- const double EPS = 1e-9;
- const double PI = 3.14159265359;
- li gcd(li a, li b) {
- return (b == 0 ? a : gcd(b, a % b));
- }
- int main() {
- //#ifdef _DEBUG
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- //#endif
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n;
- cin >> n;
- vector<vector<char>> t(n - 2, vector<char>(n - 2));
- //обработка имеющегося тайла
- forn(i, n) {
- string s;
- cin >> s;
- if (i != 0 && i != n - 1) {
- for (int j = 1; j < s.size() - 1; ++j)
- t[i - 1][j - 1] = s[j];
- }
- }
- set <vector<vector<char>>> ts;
- ts.insert(t);
- //исключительные повороты тайла
- forn(x, 3) {
- vector<vector<char>> nw(n - 2, vector<char>(n - 2));
- forn(i, n - 2)
- forn(j, n - 2)
- nw[i][j] = t[j][n - 2 - 1 - i];
- t = nw;
- ts.insert(t);
- }
- int h, w;
- cin >> h >> w;
- int hn = h / (n - 1);
- int wn = w / (n - 1);
- //привели поле к нормальному виду
- vector<vector<char>> p(hn * (n - 2) + (n - 2) * 2);
- forn(i, wn * (n - 2) + (n - 2) * 2) {
- forn(j, n - 2) {
- p[j].pb('.');
- p[p.size() - 1 - j].pb('.');
- }
- }
- int ih = n - 2;
- forn(i, n - 2) p[ih].pb('.');
- forn(i, h) {
- forn(j, w) {
- char t;
- cin >> t;
- if (i % (n - 1) != 0 && j % (n - 1) != 0) {
- p[ih].pb(t);
- }
- }
- if (i % (n - 1) != 0) {
- forn(q, n - 2) p[ih].pb('.');
- ih++;
- if (ih != p.size() - (n - 2)) forn(q, n - 2) p[ih].pb('.');
- }
- }
- forn(i, hn * (n - 2) + (n - 2) * 2) {
- forn(j, p[i].size())
- cout << p[i][j];
- cout << endl;
- }
- int ans = 0;
- //пытаемся подставлять тайлы на место точек
- for (int i = 0; i < hn * (n - 2) + (n - 2) * 2; i += (n - 2)) {
- for (int j = 0; j < wn * (n - 2) + (n - 2) * 2; j += (n - 2)) {
- if (p[i][j] == '.') { //появилось место под тайл
- for (auto cur : ts) {
- bool bor = false; //количество непустых границ
- bool ok = true; //все совпадает
- cout << i << " " << j << " ";
- if (i != 0) { //сверяем с верхней
- forn(x, n - 2) {
- if (p[i - 1][x] != cur[0][x] && p[i - 1][x] != '.') ok = false;
- if (p[i - 1][x] != '.') bor = true;
- }
- }
- cout << "up ";
- if (j != 0) { //сверяем с левой
- forn(x, n - 2) {
- if (p[x][j - 1] != cur[x][0] && p[x][j - 1] != '.') ok = false;
- if (p[x][j - 1] != '.') bor = true;
- }
- }
- cout << "left ";
- if (i + (n - 2) < p.size()) { //сверяем с нижней
- forn(x, n - 2) {
- if (p[i + (n - 2)][j + x] != cur[n - 1][x] && p[i + (n - 2)][j + x] != '.') ok = false;
- if (p[i + (n - 2)][j + x] != '.') bor = true;
- }
- }
- cout << "down ";
- if (j + (n - 2) < p[0].size()) { //сверяем с правой
- forn(x, n - 2) {
- if (p[x][j + (n - 2)] != cur[x][n - 1] && p[x][j + (n - 2)] != '.') ok = false;
- if (p[x][j + (n - 2)] != '.') bor = true;
- }
- }
- cout << "right\n";
- if (ok && bor) ans++;
- }
- }
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement