80分求调
查看原帖
80分求调
1144759
rq_hyj楼主2024/10/28 18:41

WA在第7、8个点

#include<cstdio>
#include<iostream>
using namespace std;
int len;
int n,m,ste;
int x,y,k;
char arr[1005][1005];
int t[1005][1005];
int ans;
void ddxyz() {
	for(int i=0; i<=1000; i++) {
		for(int j=0; j<=1000; j++) {
			t[i][j]=0;
		}
	}
	ans=0;
}
int main() {
	cin>>len;
	while(len--) {
		cin>>n>>m>>ste>>x>>y>>k;
		ddxyz();
		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				cin>>arr[i][j];
			}
		}
		x--;
		y--;
		ans=1;
		t[x][y]=1;
		for(int i=1; i<=ste; i++) {
			if(k==0) {
				if(y+1<m&&arr[x][y+1]=='.') {
					y++;
				} else {
					k=1;
				}
			} else if(k==1) {
				if(x+1<m&&arr[x+1][y]=='.') {
					x++;
				} else {
					k=2;
				}
			} else if(k==2) {
				if(y-1>=0&&arr[x][y-1]=='.') {
					y--;
				} else {
					k=3;
				}
			} else {
				if(x-1>=0&&arr[x-1][y]=='.') {
					x--;
				} else {
					k=0;
				}
			}
			if(t[x][y]==0) {
				ans++;
				t[x][y]=1;
			}
		}

		printf("%d\n",ans);
	}
	return 0;
}
2024/10/28 18:41
加载中...