今天J组的T2
求问我的代码为什么会死循环,在考场上明明可以的
#include<bits/stdc++.h>
using namespace std;
const int N=1e3;
const int M=1e3;
int t;
int n,m,k;
int a[N+5][M+5];
bool vis[N+5][M+5];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int x,y,d;
int cnt;
bool check(int tx,int ty){return 1<=tx&&tx<=n&&1<=ty&&ty<=m;}
void solve()
{
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
vis[i][j]=0;
cin>>a[i][j];
}
}
cnt=0;
while(k--)
{
int tx=x+dx[d];
int ty=y+dy[d];
if(check(tx,ty)&&a[tx][ty]=='.')
{
x=tx;y=ty;
if(!vis[tx][ty]) cnt++;
vis[tx][ty]=1;
}
else d=(d+1)%4;
}
cout<<cnt<<endl;
}
int main()
{
cin>>t;
while(t--) solve();
return 0;
}