a1Ex999 @ 2024-11-10 20:04:05
#include <bits/stdc++.h>
using namespace std;
long long t,n,m,k,x,y,d,sum=1;
char s;
int main(){
cin>>t;
for(int i=1;i<=t;i++){
sum=1;
cin>>n>>m>>k;
cin>>x>>y>>d;
bool tib[n+10][m+10],tmb[n+10][m+10];
for(int j=1;j<=n;j++){
for(int z=1;z<=m;z++){
cin>>s;
if(s=='x') tib[j][z]=1;
}
}
for(int o=1;o<=k;o++){
tmb[x][y]=1;
if(d==0&&tib[x][y+1]==0&&y<m){
if(tmb[x][y+1]==0) sum++;
y++;
}else if(d==1&&tib[x+1][y]==0&&x<n){
if(tmb[x+1][y]==0) sum++;
x++;
}else if(d==2&&tib[x][y-1]==0&&y>1){
if(tmb[x][y-1]==0) sum++;
y--;
}else if(d==3&&tib[x-1][y]==0&&x>1){
if(tmb[x-1][y]==0) sum++;
x--;
}else{
d=(d+1)%4;
}
}
cout<<sum<<endl;
}
return 0;
}
by hujianyue_i @ 2024-11-10 20:35:44
tib,tmb数组没有清空,就改了那一处
#include <bits/stdc++.h>
using namespace std;
long long t,n,m,k,x,y,d,sum=1;
char s;
bool tib[1010][1010],tmb[1010][1010];
int main(){
cin>>t;
for(int i=1;i<=t;i++){
sum=1;
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int j=1;j<=n;j++){
for(int z=1;z<=m;z++){
cin>>s;
tmb[j][z]=0;
if (s=='x'){
tib[j][z]=1;
}
else if (s=='.'){
tib[j][z]=0;
}
}
}
for(int o=1;o<=k;o++){
tmb[x][y]=1;
if(d==0&&tib[x][y+1]==0&&y<m){
if(tmb[x][y+1]==0) sum++;
y++;
}else if(d==1&&tib[x+1][y]==0&&x<n){
if(tmb[x+1][y]==0) sum++;
x++;
}else if(d==2&&tib[x][y-1]==0&&y>1){
if(tmb[x][y-1]==0) sum++;
y--;
}else if(d==3&&tib[x-1][y]==0&&x>1){
if(tmb[x-1][y]==0) sum++;
x--;
}else{
d=(d+1)%4;
}
}
cout<<sum<<endl;
}
return 0;
}
by hujianyue_i @ 2024-11-10 20:39:40
@ a1Ex999
by hujianyue_i @ 2024-11-10 20:40:16
@a1Ex999
by a1Ex999 @ 2024-11-10 21:09:52
@hujianyue_i已关 ,感谢
by WElastkiss @ 2024-11-10 21:47:00
路过
by zyw2012 @ 2024-12-29 11:36:17
好厉害欸、、、