wenxuliang @ 2024-11-04 22:22:40
#include<bits/stdc++.h>
using namespace std;
long long t,n,m,k,x,y,d,s;
int b[1005][1005];
int px[10]={1,0,-1,0};
int py[10]={0,1,0,-1};
char a[1005][1005],w;
void f(long long xx,long long yy,long long dd,long long kk){
if(kk==0){
return;
}
if(a[xx+py[dd]][yy+px[dd]]=='.'){
if(b[xx+py[dd]][yy+px[dd]]==0){
s++;
b[xx+py[dd]][yy+px[dd]]=1;
}
//cout<<xx+py[dd]<<" "<<yy+px[dd]<<"\n";
f(xx+py[dd],yy+px[dd],dd,kk-1);
}
else{
//cout<<(dd+1)%4<<"\n";
f(xx,yy,(dd+1)%4,kk-1);
}
}
int main(){
//freopen("explore.in","r",stdin);
//freopen("explore.out","w",stdout);
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>m>>k;
cin>>x>>y>>d;
s=1;
for(int j=1;j<=n;j++){
for(int l=1;l<=m;l++)a[j][l]=0,b[j][l]=0;
}
for(int j=1;j<=n;j++){
for(int l=1;l<=m;l++){
cin>>a[j][l];
}
}
f(x,y,d,k);
cout<<s<<"\n";
}
return 0;
}
by FarmerDrone @ 2024-11-04 22:30:09
是不是要给起点打个访问标记 @wenxuliang
by wenxuliang @ 2024-11-04 22:36:21
但是40
#include<bits/stdc++.h>
using namespace std;
long long t,n,m,k,x,y,d,s;
int b[1005][1005];
int px[10]={1,0,-1,0};
int py[10]={0,1,0,-1};
char a[1005][1005],w;
void f(long long xx,long long yy,long long dd,long long kk){
if(kk==0){
return;
}
if(a[xx+py[dd]][yy+px[dd]]=='.'){
if(b[xx+py[dd]][yy+px[dd]]==0){
s++;
b[xx+py[dd]][yy+px[dd]]=1;
}
//cout<<xx+py[dd]<<" "<<yy+px[dd]<<"\n";
f(xx+py[dd],yy+px[dd],dd,kk-1);
}
else{
//cout<<(dd+1)%4<<"\n";
f(xx,yy,(dd+1)%4,kk-1);
}
}
int main(){
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>m>>k;
cin>>x>>y>>d;
s=1;
for(int j=1;j<=n;j++){
for(int l=1;l<=m;l++)a[j][l]=0,b[j][l]=0;
}
for(int j=1;j<=n;j++){
for(int l=1;l<=m;l++){
cin>>a[j][l];
}
}
f(x,y,d,k);
b[x][y]=1;
cout<<s<<"\n";
}
return 0;
}
@FarmerDrone
by FarmerDrone @ 2024-11-05 12:11:34
@wenxuliang ? 不应该写在f函数前面吗?
by wenxuliang @ 2024-11-06 12:29:01
@FarmerDrone 但是70分(尴尬
#include<bits/stdc++.h>
using namespace std;
long long t,n,m,k,x,y,d,s;
int b[1005][1005];
int px[10]={1,0,-1,0};
int py[10]={0,1,0,-1};
char a[1005][1005],w;
void f(long long xx,long long yy,long long dd,long long kk){
b[xx][yy]=1;
if(kk==0){
return;
}
if(a[xx+py[dd]][yy+px[dd]]=='.'){
if(b[xx+py[dd]][yy+px[dd]]==0){
s++;
b[xx+py[dd]][yy+px[dd]]=1;
}
//cout<<xx+py[dd]<<" "<<yy+px[dd]<<"\n";
f(xx+py[dd],yy+px[dd],dd,kk-1);
}
else{
//cout<<(dd+1)%4<<"\n";
f(xx,yy,(dd+1)%4,kk-1);
}
}
int main(){
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>m>>k;
cin>>x>>y>>d;
s=1;
for(int j=1;j<=n;j++){
for(int l=1;l<=m;l++)a[j][l]=0,b[j][l]=0;
}
for(int j=1;j<=n;j++){
for(int l=1;l<=m;l++){
cin>>a[j][l];
}
}
f(x,y,d,k);
cout<<s<<"\n";
}
return 0;
}