WEICY123 @ 2024-11-09 18:24:15
#include<bits/stdc++.h>
using namespace std;
int n,m,k,x0,sy0,d0,ans=0;
int t,b[1001][1001];
char a[1001][1001];
int main(){
cin>>t;
while(t--){
memset(b,0,sizeof(0));
ans=0;
cin>>n>>m>>k>>x0>>sy0>>d0;
b[x0][sy0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
while(k--){
if(d0==0){
int y1=sy0+1;
if(x0>=1&&x0<=n&&y1>=1&&y1<=m&&a[x0][y1]=='.'){
sy0=sy0+1;
b[x0][sy0]=1;
}
else d0=(d0+1)%4;
}
else if(d0==1){
int x1=x0+1;
if(x1>=1&&x1<=n&&sy0>=1&&sy0<=m&&a[x1][sy0]=='.'){
x0=x0+1;
b[x0][sy0]=1;
}
else d0=(d0+1)%4;
}
else if(d0==2){
int y1=sy0-1;
if(x0>=1&&x0<=n&&y1>=1&&y1<=m&&a[x0][y1]=='.'){
sy0=sy0-1;
b[x0][sy0]=1;
}
else d0=(d0+1)%4;
}
else if(d0==3){
int x1=x0-1;
if(x1>=1&&x1<=n&&sy0>=1&&sy0<=m&&a[x1][sy0]=='.'){
x0=x0-1;
b[x0][sy0]=1;
}
else d0=(d0+1)%4;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(b[i][j]==1)ans++;
}
}
cout<<ans<<endl;
}
}
by xizixun_watermellon @ 2024-11-09 18:48:46
#include<bits/stdc++.h>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int t,n,m,k,x,y,d,a[1009][1009],ans;
char c[1009][1009];
int main(){
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>m>>k>>x>>y>>d;
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
cin>>c[j][k];
}
}
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
a[j][k]=0;
}
}
a[x][y]=1;
ans=1;
for(int j=1;j<=k;j++){
if(c[x+dx[d]][y+dy[d]]=='x'||x+dx[d]>n||x+dx[d]<1||y+dy[d]>m||y+dy[d]<1){
d++;
if(d==4){
d=0;
}
}else{
if(a[x+dx[d]][y+dy[d]]==0){
a[x+dx[d]][y+dy[d]]=1;
ans++;
}
x+=dx[d];
y+=dy[d];
}
}
cout<<ans<<endl;
}
return 0;
}
应该看得懂吧?
@WEICY123
by w3292531438 @ 2024-11-15 17:11:48
问题很简单,经过了的格子既就不能在计数了,代码里需要标记一下哪些格子已经经过了
by WEICY123 @ 2024-11-16 16:14:00
@w3292531438已经找到错误了