kingsleykingsley @ 2024-11-07 12:58:30
#include <iostream>
#include <cstring>
using namespace std;
bool vis[1005][1005];
char mp[1005][1005];
int main()
{
int T;
cin >> T;
while(T--)
{
memset(vis, 0, sizeof vis);
int n, m, k;
cin >> n >> m >> k;
int x, y, d;
cin >> x >> y >> d;
for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> mp[i][j];
for(int i = 1; i <= k; i++)
{
int nx = x, ny = y;
if(d == 0) ny++;
if(d == 1) nx++;
if(d == 2) ny--;
if(d == 3) nx--;
if(1 <= nx && nx <= n && 1 <= ny && ny <= m && mp[nx][ny] == '.')
{
vis[nx][ny] = 1;
x = nx, y = ny;
}
else d = (d + 1) % 4;
}
int cnt = 1;
for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cnt += vis[i][j];
cout << cnt << endl;
}
return 0;
}
by xujiacheng0312 @ 2024-11-07 13:03:44
#include<bits/stdc++.h>
using namespace std;
int n,m,k,a[1010][1010],ans=1;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
void f(int x,int y,int d,int s){
if(s==k)
return;
int xx=x+dx[d],yy=y+dy[d];
if(a[xx][yy]==-1) f(x,y,(d+1)%4,s+1);
else{
if(a[xx][yy]==0) ans++,a[xx][yy]=1;
f(xx,yy,d,s+1);
}
}
int main(){
int t;
cin>>t;
while(t--){
memset(a,-1,sizeof(a));
ans=1;
int sx,sy,sd;
cin>>n>>m>>k>>sx>>sy>>sd;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
char c;
cin>>c;
if(c=='x') a[i][j]=-1;
else a[i][j]=0;
}
a[sx][sy]=1;
f(sx,sy,sd,0);
cout<<ans<<endl;
}
return 0;
}
by xujiacheng0312 @ 2024-11-07 13:04:20
@kingsleykingsley
你好
by Are_you_sure_cjj @ 2024-11-08 21:05:25
#include<bits/stdc++.h>
using namespace std;
char M[1005][1005];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int vis[1005][1005];
int main(){
int T,n,m,cnt,k,x,y,d,ny,nx;
cin>>T;
while(T--)
{
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=0;i<1005;i++)
for(int j=0;j<1005;j++)
M[i][j]='x',vis[i][j]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>M[i][j];
}
cnt=1;
vis[x][y]=1;
while(k--){
nx=x+dx[d],ny=y+dy[d];
if(M[nx][ny]=='x'){d=(d+1)%4;continue;}
x=nx,y=ny;
if(!vis[x][y]) vis[x][y]=1,cnt++;
}
cout<<cnt<<endl;
}
return 0;
}
by Are_you_sure_cjj @ 2024-11-08 21:05:44
@kingsleykingsley 你好