50分,求助
查看原帖
50分,求助
1098582
bzz_ZhangHongrui楼主2024/10/26 22:07
#include <iostream>
using namespace std;

const int N = 1000 + 10;

int main() {
	int t;
	cin>>t;
	
	while (t--) {
		int n, m, k;
		int x, y, d;
		cin>>n>>m>>k;
		cin>>x>>y>>d;
		
		char c[N][N];
		bool st[N][N];
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				cin>>c[i][j];
				st[i][j] = false;
			}
		}
		
		int sum = 1;
		while (k != 0) {
			if (d == 0) {
				if (1 <= x && x <= n && 1 <= y + 1 && y + 1 <= m && c[x][y + 1] == '.') {
					y++;
					k--;
					if (st[x][y] == false) {
						sum++;
						st[x][y] = true;
					}
				} else {
					d = (d + 1) % 4;
					k--;
				}
			} else if (d == 1) {
				if (1 <= x + 1 && x + 1 <= n && 1 <= y && y <= m && c[x + 1][y] == '.') {
					x++;
					k--;
					if (st[x][y] == false) {
						sum++;
						st[x][y] = true;
					}
				} else {
					d = (d + 1) % 4;
					k--;
				}
			} else if (d == 2) {
				if (1 <= x && x <= n && 1 <= y - 1 && y - 1 <= m && c[x][y - 1] == '.') {
					y--;
					k--;
					if (st[x][y] == false) {
						sum++;
						st[x][y] = true;
					}
				} else {
					d = (d + 1) % 4;
					k--;
				}
			} else if (d == 3) {
				if (1 <= x - 1 && x - 1 <= n && 1 <= y && y <= m && c[x - 1][y] == '.') {
					x--;
					k--;
					if (st[x][y] == false) {
						sum++;
						st[x][y] = true;
					}
				} else {
					d = (d + 1) % 4;
					k--;
				}
			}
		}
		cout<<sum<<endl;
	}
	
	return 0;
}
2024/10/26 22:07
加载中...