40分求助,检查不出来了,感觉模拟是对的啊
查看原帖
40分求助,检查不出来了,感觉模拟是对的啊
1629940
Nexara楼主2025/7/18 23:53
#include<bits/stdc++.h>
using namespace std;
int t,n,m,k,x,y,d,ans;
char s[1005][1005];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	for(int i=1;i<=t;i++) {
		ans=1;
		cin>>n>>m>>k>>x>>y>>d;
		for(int j=1;j<=n;j++)
			for(int l=1;l<=m;l++)
				cin>>s[j][l];
		for(int j=1;j<=k;j++) {
			if(d==0) {
				if(s[x][y+1]=='.'&&y+1<=m) {
					y++;
					ans++;
				}
				else
					d=(d+1)%4;
			}
			else if(d==1) {
				if(s[x+1][y]=='.'&&x+1<=n) {
					x++;
					ans++;
				}
				else
					d=(d+1)%4;
			}
			else if(d==2) {
				if(s[x][y-1]=='.'&&y-1>=1) {
					y--;
					ans++;
				}
				else
					d=(d+1)%4;
			}
			else if(d==3) {
				if(s[x-1][y]=='.'&&x-1>=1) {
					x--;
					ans++;
				}
				else
					d=(d+1)%4;
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}
2025/7/18 23:53
加载中...