KMemory @ 2024-10-27 13:36:07
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T;
int n,m,k;
int x,y,d;
char a[1001][1001];
bool b[1001][1001];
signed main()
{
cin>>T;
for(int t=1;t<=T;t++)
{
int ans=1;
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j]=='x')
b[i][j]=false;
else
b[i][j]=true;
}
for(int i=1;i<=k;i++)
{
int dx,dy;
if(d==0)
dx=x,dy=y+1;
else if(d==1)
dx=x+1,dy=y;
else if(d==2)
dx=x,dy=y-1;
else if(d==3)
dx=x-1,dy=y;
if(dx>n||dx<1||dy<1||dy>m||a[dx][dy]=='x')
{
d=(d+1)%4;
continue;
}
x=dx;y=dy;
if(b[x][y]==true)
ans++;
b[x][y]=false;
}
cout<<ans<<endl;
}
return 0;
}
by Maoyankai @ 2024-10-27 15:03:06
#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,k;
int x,y,d;
char a[1003][1003];
bool b[1003][1003];
int main(){
cin>>T;
for(int t=1;t<=T;t++){
int ans=1;
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]=='x')
b[i][j]=false;
else
b[i][j]=true;
}
b[x][y]=false;
for(int i=1;i<=k;i++){
int dx,dy;
if(d==0)
dx=x,dy=y+1;
else if(d==1)
dx=x+1,dy=y;
else if(d==2)
dx=x,dy=y-1;
else if(d==3)
dx=x-1,dy=y;
if(dx>n||dx<1||dy<1||dy>m||a[dx][dy]=='x'){
d=(d+1)%4;
continue;
}
x=dx;
y=dy;
if(b[x][y]==true)
ans++;
b[x][y]=false;
}
cout<<ans<<endl;
}
return 0;
}
by KMemory @ 2024-10-27 15:29:40
@Maoyankai 为啥这样啊