40pts 悬棺求调
查看原帖
40pts 悬棺求调
1323415
wky_wsy_楼主2025/1/12 14:13
#include <iostream>
#include <cstring>
using namespace std;
char a[1145][1145];
bool b[1145][1145];
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, m, k, x, y, d;
		cin >> n >> m >> k;
		cin >> x >> y >> d;
		int c = 1;
		memset(b, 0, sizeof(b));
		memset(a, 0, sizeof(a));
		for (int i = 1;i <= n;i++) {
			for (int j = 1;j <= m;j++) {
				cin >> a[i][j];
			}
		}
		while (k--) {
			int lx = x + dx[d], ly = y + dy[d];
			if (a[lx][ly] == '.' && b[lx][ly] == false) {//重置后a数组没有输入的部分都是空字符
				++c;
				x = lx;
				y = ly;
			}
			else {
				d = (d + 1) % 4;
			}
		}
		cout << c << endl;
	}
}
2025/1/12 14:13
加载中...