为什么0分??
查看原帖
为什么0分??
1545333
jiang_shi_qi楼主2024/10/26 21:55
#include<bits/stdc++.h>
using namespace std;
char a[1010][1010];
bool b[1010][1010];
int n, m, k, x, y, d;
int main(){
	freopen("explore.in", "r", stdin);
	freopen("explore.out", "w", stdout);
	int T;
	cin >> T;
	while(T--){
		cin >> n >> m >> k >> x >> y >> d;
		for(int i = 1; i <= n; i++){
			for(int j = 1;j <= m; j++){
				cin >> a[i][j];
			}
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				b[i][j] = false;
			}
		}
		b[x][y] = true;
		while(k--){
			if(d == 0){
				if(x >= 1 and x <= n and y + 1 >= 1 and y + 1 <= m and a[x][y + 1] == '.'){
					x = x;
					y++;
				}else{
					d = (d + 1) % 4;
				}
			}else if(d == 1){
				if(x + 1 >= 1 and x + 1 <= n and y >= 1 and y <= m and a[x + 1][y] == '.'){
					x++;
					y = y;
				}else{
					d = (d + 1) % 4;
				}
			}else if(d == 2){
				if(x >= 1 and x <= n and y - 1 >= 1 and y - 1 <= m and a[x][y - 1] == '.'){
					x = x;
					y--;
				}else{
					d = (d + 1) % 4;
				}
			}else if(d == 3){
				if(x - 1 >= 1 and x - 1 <= n and y >= 1 and y <= m and a[x - 1][y] == '.'){
					x--;
					y = y;
				}else{
					d = (d + 1) % 4;
				}
			}
			b[x][y] = true;
		}
		int ans = 0;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				if(b[i][j]){
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}
2024/10/26 21:55
加载中...