zhouxiangrong @ 2024-11-06 21:50:55
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
char l[N][N];
int f[N][N];
int main()
{
//freopen("explore.in","r",stdin);
//freopen("explore.out","w",stdout);
int n;
cin>>n;
while(n--)
{
int a,b,c,x,y,d,cnt=0;
cin>>a>>b>>c>>x>>y>>d;
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
cin>>l[i][j];
f[i][j]=0;
}
}
f[x][y]=1;
for(int i=1;i<=c;i++)
{
if(d==0)
{
if(l[x][y+1]=='.')
{
y++;
f[x][y]=1;
}
else
{
d=(d+1)%4;
}
}
else if(d==1)
{
if(l[x+1][y]=='.')
{
x++;
f[x][y]=1;
}
else
{
d=(d+1)%4;
}
}
else if(d==2)
{
if(l[x][y-1]=='.')
{
y--;
f[x][y]=1;
}
else
{
d=(d+1)%4;
}
}
else if(d==3)
{
if(l[x-1][y]=='.')
{
x--;
f[x][y]=1;
}
else
{
d=(d+1)%4;
}
}
}
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
if(f[i][j]==1)
{
cnt++;
}
}
}
cout<<cnt<<endl;
}
return 0;
}
by yangyuhan_yyh @ 2024-11-08 20:36:39
#include<bits/stdc++.h>
using namespace std;
int n,m,k,x,y,d,b[1001][1001];
char a[1001][1001];
int main(){
int t;cin>>t;
for(int q=1;q<=t;q++){
long long sum=0,ans=0;
cin>>n>>m>>k>>x>>y>>d;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];b[i][j]=0;
if(a[i][j]=='.')ans++;
}
}b[x][y]=1;
while(k>0&&ans>0){
while((k>0)&&((d==0&&a[x][y+1]=='x')||(d==1&&a[x+1][y]=='x')||(d==2&&a[x][y-1]=='x')||(d==3&&a[x-1][y]=='x')||(d==0&&y+1>m)||(d==1&&x+1>n)||(d==2&&y-1<=0)||(d==3&&x-1<=0))){
d=(d+1)%4,k--;
}if(d==0)y++;
else if(d==1)x++;
else if(d==2)y--;
else if(d==3)x--;
k--;if(k>=0){
b[x][y]++;
if(b[x][y]==1)ans--;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(b[i][j]!=0)sum++;
}
}cout<<sum<<endl;
}
return 0;
}