70分求调,样例全对,7、8、10WA
查看原帖
70分求调,样例全对,7、8、10WA
1279073
nowornever0625楼主2024/10/26 22:31
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;

char Map[N][N];
bool vis[N][N];

int main() {
	//d=0东 1南 2西 3北
//	freopen("tmp.in", "r", stdin);
	int T;
	int n, m, k, x0, y0, d0, ans, x, y, d;
	cin >> T;
	while (T--) {
		memset(vis, 0, sizeof(vis));
		cin >> n >> m >> k >> x0 >> y0 >> d0;
		for (int i = 1; i <= n; i++) {
			string a;
			cin >> a;
			for (int j = 1; j <= m; j++)
				Map[i][j] = a[j - 1];
		}
		x = x0, y = y0, d = d0;
		while (k--) {
//			cout << x << y << ' ' << k << endl;
			ans = 0;
			vis[x][y] = 1;
			if (d == 0) {
				if (Map[x][y + 1] == '.')
					y++, vis[x][y] = 1;
				else {
					d = (d + 1) % 4;
					continue;
				}
			}
			if (d == 1) {
				if (Map[x + 1][y] == '.')
					x++, vis[x][y] = 1;
				else {
					d = (d + 1) % 4;
					continue;
				}
			}
			if (d == 2) {
				if (Map[x][y - 1] == '.')
					y--, vis[x][y] = 1;
				else {
					d = (d + 1) % 4;
					continue;
				}
			}
			if (d == 3) {
				if (Map[x - 1][y] == '.')
					x--, vis[x][y] = 1;
				else {
					d = (d + 1) % 4;
					continue;
				}
			}
		}
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				ans += vis[i][j];
		cout << ans << endl;
	}
	return 0;
}
2024/10/26 22:31
加载中...