求助
查看原帖
求助
637788
kimi0705楼主2023/8/3 16:38

总是多一个

#include <bits/stdc++.h>
using namespace std;
const int mxn = 2020;
int n, m, r, c, max__L, max__R, cnt;
char mp[mxn][mxn];
int LL[2020][2020], RR[2020][2020];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
struct que_mode {
	int x, y, L, R;
};
queue<que_mode> Q;
bool check(int x, int y) {
	return x > 0 && y > 0 && x <= n && y <= m && mp[x][y] != '*';
}
int main() {
	cin >> n >> m >> r >> c >> max__L >> max__R;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%c", &mp[i][j]), LL[i][j] = RR[i][j] = INT_MAX;
	Q.push({r, c, max__L, max__R}), mp[r][c] = '-', LL[r][c] = RR[r][c] = 0, cnt++;
	while (Q.size()) {
		que_mode x = Q.front();
		Q.pop();
		for (int i = 0; i < 4; i++) {
			int Now__x = x.x + dx[i];
			int Now__y = x.y + dy[i];
			if (!check(Now__x, Now__y)) continue;
			if (mp[Now__x][Now__y] != '-') {
				if (i == 2) {
					if (x.R == 0)continue;
					Q.push({Now__x, Now__y, x.L, x.R - 1}), mp[Now__x][Now__y] = '-', cnt++;
				} else if (i == 3) {
					if (x.L == 0) continue;
					Q.push({Now__x, Now__y, x.L - 1, x.R}), mp[Now__x][Now__y] = '-', cnt++;
				} else {
					Q.push({Now__x, Now__y, x.L, x.R}), mp[Now__x][Now__y] = '-', cnt++;
				}
			} else {
				if (i == 2) {
					if (x.R == 0) continue;
					if (x.L <= LL[Now__x][Now__y] && x.R - 1 <= RR[Now__x][Now__y]) continue;
					if (x.L >= LL[Now__x][Now__y] && x.R - 1 >= RR[Now__x][Now__y]) {
						LL[Now__x][Now__y] = x.L, RR[Now__x][Now__y] = x.R - 1;
					}
					Q.push({Now__x, Now__y, x.L, x.R - 1});
				} else if (i == 3) {
					if (x.L == 0) continue;
					if (x.L - 1 <= LL[Now__x][Now__y] && x.R <= RR[Now__x][Now__y]) continue;
					if (x.L - 1 >= LL[Now__x][Now__y] && x.R >= RR[Now__x][Now__y]) {
						LL[Now__x][Now__y] = x.L - 1, RR[Now__x][Now__y] = x.R;
					}
					Q.push({Now__x, Now__y, x.L - 1, x.R});
				} else {
					if (x.L <= LL[Now__x][Now__y] && x.R <= RR[Now__x][Now__y]) continue;
					if (x.L >= LL[Now__x][Now__y] && x.R >= RR[Now__x][Now__y]) {
						LL[Now__x][Now__y] = x.L, RR[Now__x][Now__y] = x.R;
					}
					Q.push({Now__x, Now__y, x.L, x.R});
				}
			}
		}
	}
	cout << cnt << '\n';
	return 0;
}
2023/8/3 16:38
加载中...