求助#样例过了但是50分
查看原帖
求助#样例过了但是50分
1181194
mathsfox楼主2025/7/22 21:16
#include <bits/stdc++.h>
using namespace std;
int t;//组数
char s[1009][1009];
bool use[1009][1009] = {0};
const int dirx[] = {0, 1, 0, -1};
const int diry[] = {1, 0, -1, 0};
	int main() {
		cin >> t;
		while (t--) {
			int n, m, k, x1, y1, d1;
			cin >> n >> m >> k >> x1 >> y1 >> d1;
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					cin >> s[i][j];
				}
			}
			int a = x1, b = y1, move = d1 ,ans=0;
			int p, q;
			while (k--) {
				p = a + dirx[move];
				q = b + diry[move];
				if (p <= n && q <= m && s[p][q] == '.' && p >= 1 && q >= 1) {
					if (!use[p][q]) {
						use[p][q] = 1;
						ans++;
					}
					a = p;
					b = q;
				} else {
					move = (move + 1) % 4;
				}
			}
			cout<<ans+1<<"\n";
			memset(use, 0, sizeof(use));
		}
		return 0;
	}
2025/7/22 21:16
加载中...