40pts求调
查看原帖
40pts求调
1044126
HaloCode楼主2024/11/6 22:13
#include<bits/stdc++.h>

using namespace std;

const int MAXN = 1e3 + 10;

struct Node{
	long long x, y, d;
};

int T;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

int main(){

	
	cin >> T;
	while(T--){
		long long n, m, k, sx, sy, sd;
		char dt[MAXN][MAXN] = {0};
		bool bj[MAXN][MAXN] = {0};
		
		cin >> n >> m >> k;
		cin >> sx >> sy >> sd;
		for(int i = 1; i <= n; i++){
			string s;
			cin >> s;
			for(int j = 0; j < s.size(); j++){
				dt[i][j + 1] = s[j];
			}
		}

		//bfs
		
		Node dl[MAXN];
		long long head = 1, tail = 0, op = 0;
		dl[head].x = sx;
		dl[head].y = sy;
		dl[head].d = sd;
		bj[sx][sy] = 1;
		tail++;

		while(head <= tail && k > 0){
			int a = 0; 
			op = 0;
			int od = dl[head].d;
			int ox = dl[head].x + dx[od];
			int oy = dl[head].y + dy[od];
			if(bj[ox][oy] == 0){
				if(ox >= 1 && ox <= n && oy >= 1 && oy <= m && dt[ox][oy] == '.'){
					tail++;
					dl[tail].x = ox;
					dl[tail].y = oy;
					dl[tail].d = od;
					bj[ox][oy] = 1;
				}else{
					op = 1;
					dl[tail].d = (od + 1) % 4;
				}
				
			}
			if(op == 0){
				head++;
			}
			k--;
		}
		
		long long cnt = 0;
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= m; j++){
				if(bj[i][j] > 0){
					cnt++;
				}
			}
		}
		cout << cnt << endl;
}
return 0;
}

2024/11/6 22:13
加载中...