xjhjtz0320 @ 2024-11-10 09:12:14
#include<bits/stdc++.h>
using namespace std;
int vis[2000][2000];
int main()
{
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
char s[2000][2000];
int x=0,y=0,x0,y0,m,n,t,d=0,d0,k;
cin>>t;
while(t--)
{
cin>>n>>m>>k;
cin>>x0>>y0>>d0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>s[i][j];
int ans=1;
memset(vis,0,sizeof(vis));
//vis[x][y]=0;
while(k--)
{
int x=x0+dx[d0];y=y0+dy[d0];
if(x>=1&&x<=n&&y>=1&&y<=m&&s[x][y]=='.')
{
if(vis[x][y]==0) ans++;
vis[x][y]=1;
x0=x;
y0=y;
}
else d0=(d0+1)%4;
}
cout<<ans;
}
}
by kevinf @ 2024-11-10 11:40:15
#include<bits/stdc++.h>
using namespace std;
int vis[2000][2000];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
char s[2000][2000];
int x=0,y=0,xx,yy,m,n,t,d=0,d0,k;
int main(){
// freopen("expolre3.in","r",stdin);
cin>>t;
while(t--)
{
cin>>n>>m>>k;
cin>>xx>>yy>>d0;
for(int i=1;i<=n;i++)
// for(int j=1;j<=m;j++)
cin>>s[i]+1;
int ans=1;
memset(vis,0,sizeof(vis));
vis[xx][yy]=1;
while(k--)
{
x=xx+dx[d0];y=yy+dy[d0];
// cout<<x<<" "<<y<<" "<<d0<<endl;
if(x>=1&&x<=n&&y>=1&&y<=m&&s[x][y]=='.')
{
if(vis[x][y]==0) ans++;
vis[x][y]=1;
xx=x;
yy=y;
}
else d0=(d0+1)%4;
}
cout<<ans<<endl;;
}
return 0;
}
@xjhjtz0320 已AC