1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream> #include <algorithm> #include <cstring> #include <queue> #include <unordered_map>
using namespace std;
const int N = 10010; int n, m; int cnt; char g[15][15]; string s[15]; int v[15][15]; int nw[15]; int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
void dfs(int x, int y);
int main() { int n; cin >> n; for (int i = 1; i <= 8; ++i) for (int j = 1; j <= 8; ++j) cin >> g[i][j]; for (int i = 1; i <= 8; ++i) cin >> s[i]; while (n --) { int x, y; char op; cin >> x >> y >> op; for (int i = 1; i <= 8; ++i) for (int j = 1; j <= 8; ++j) v[i][j] = 0;
cnt = 0; dfs(x, y); printf("%d\n", cnt);
if (op == 'w') { for (int j = 1; j <= 8; ++j) { vector<char> tmp; tmp.clear(); for (int i = 1; i <= 8; ++i) if (!v[i][j]) tmp.push_back(g[i][j]); for (int i = 0; i < tmp.size(); ++i) g[i + 1][j] = tmp[i]; for (int i = tmp.size() + 1; i <= 8; ++i) g[i][j] = s[j][nw[j] ++]; } } else if (op == 's') { for (int j = 1; j <= 8; ++j) { vector<char> tmp; tmp.clear(); for (int i = 1; i <= 8; ++i) if (!v[i][j]) tmp.push_back(g[i][j]); for (int i = 8, k = tmp.size() - 1; k >= 0; --i, --k) g[i][j] = tmp[k]; for (int i = 8 - tmp.size(); j >= 1; --j) g[i][j] = s[j][nw[j]++]; } } else if (op == 'a') { for (int i = 1; i <= 8; ++i) { vector<char> tmp; tmp.clear(); for (int j = 1; j <= 8; ++j) if (!v[i][j]) tmp.push_back(g[i][j]); for (int j = 0; j < tmp.size(); ++j) g[i][j + 1] = tmp[j]; for (int j = tmp.size() + 1; j <= 8; ++j) g[i][j] = s[i][nw[i]++]; } } else if (op == 'd') { for (int i = 1; i <= 8; ++i) { vector<char> tmp; tmp.clear(); for (int j = 1; j <= 8; ++j) if (!v[i][j]) tmp.push_back(g[i][j]); for (int j = 8, k = tmp.size() - 1; k >= 0; --j, --k) g[i][j] = tmp[k]; for (int j = 8 - tmp.size(); j >= 1 ; --j) g[i][j] = s[i][nw[i]++]; } } } return 0; }
void dfs(int x, int y) { v[x][y] = 1; cnt ++; for (int i = 0; i < 4; ++i) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 1 || nx > 8 || ny < 1 || ny > 8 || v[nx][ny] || g[x][y] != g[nx][ny]) continue; dfs(nx, ny); } }
|