Xyfiiae_n @ 2024-11-11 13:35:48
#include <iostream>
using namespace std;
int m,n,k,x,y,d,t,T;
int mo[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int ma[1000][1000],jg[5];
int dfs(int x,int y,int d)
{
int nx,ny,tu=d;
if(t>k)
return 0;
ma[x][y]=2;
while(true)
{
if(t>k)
return 0;
nx=x+mo[tu][0];
ny=y+mo[tu][1];
if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&ma[nx][ny]!=1)
break;
tu=(tu+1)%4;
t++;
}
t++;
dfs(nx,ny,tu);
return 0;
}
int main()
{
//freopen("explore.in","r",stdin);
//freopen("explore.out","w",stdout);
cin>>T;
for(int I=0;I<T;I++)
{
char tmp;
cin>>m>>n>>k>>x>>y>>d;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
ma[i][j]=0;
cin>>tmp;
if(tmp=='x')
ma[i][j]=1;
}
dfs(x,y,d);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(ma[i][j]==2)
jg[I]++;
}
}
}
for(int I=0;I<T;I++)
cout<<jg[I]<<endl;
return 0;
}
by Xyfiiae_n @ 2024-11-11 13:40:39
全wa战绩 样例1过了
by fqzcwei @ 2024-11-11 21:46:08
@Xyfiiae_n 膜拜先修营大佬%%%%
这题不用DFS,模拟就可以