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
| #include <algorithm> #include <cstring> #include <iostream> #include <queue> using namespace std; typedef pair<int, int> PII; const int N = 25;
bool mp[N][N];
int st[N][N];
int n, m, k, l;
int bx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, by[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void count(int x, int y) { st[x][y] = 0; for (int i = 0; i < 8; i++) { int nx = x + bx[i], ny = y + by[i]; if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue; if (mp[nx][ny]) st[x][y]++; } }
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
void bfs(int x, int y) { queue<PII> q; q.push({x, y}); count(x, y); while (!q.empty()) { int x = q.front().first, y = q.front().second; q.pop(); for (int i = 0; i < 4; ++i) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || nx >= m || ny < 0 || ny >= n) continue; if (!mp[nx][ny] && st[nx][ny] == -1) { count(nx, ny); q.push({nx, ny}); } } } }
bool tap(int x, int y) { if (x < 0 || x >= m || y < 0 || y >= n) return false; if (st[x][y] != -1) return false; if (mp[x][y]) return true; bfs(x, y); return false; } bool flag = false; int main() { cin >> n >> m >> k >> l; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; mp[x][y] = true; } memset(st, -1, sizeof(st)); for (int i = 0; i < l; i++) { int x, y; cin >> x >> y; if (tap(x, y)) { cout << "You lose" << endl; flag = true; break; } else { for (int ii = 0; ii < n; ii++) { for (int jj = 0; jj < m; jj++) printf("%d ", st[ii][jj]); cout << endl; } } if (i != l - 1) cout << endl; } int cnt = 0; if (!flag) { for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) if (st[i][j] == -1) cnt++; if (cnt == k) cout << "You win" << endl; } return 0; }
|