cqxingyun @ 2024-10-26 22:25:19
考场上explore5.in(8~10号数据点)我的代码要爆栈空间,这里没爆。
#include<bits/stdc++.h>
using namespace std;
int zou[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
int n,m;
int b[1003][1003] = {};
char dix[1003][1003] = {};
void dfs(int x,int y,int d,int k){
b[x][y] = 2;
if(k == 0){
return;
}
int x1 = x+zou[d][0],y1 = y+zou[d][1];
if(x1<=n && x1>0 && y1<=m && y1>0 && b[x1][y1]!=1){
dfs(x1,y1,d,k-1);
}else{
dfs(x,y,(d+1)%4,k-1);
}
}
int main(){
int T;
cin>>T;
while(T--){
int k;
int x0,y0,d0;
cin>>n>>m>>k;
cin>>x0>>y0>>d0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>dix[i][j];
if(dix[i][j] == 'x'){
b[i][j] = 1;
}
}
}
dfs(x0,y0,d0,k);
int ans = 0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(b[i][j] == 2){
ans++;
}
}
}
cout<<ans<<endl;
memset(b,0,sizeof(b));
}
return 0;
}
by leozhao123 @ 2024-10-26 22:28:22
@cqxingyun 编译器有默认栈空间限制,可能会报错,但这题里栈有 512 MB。
by leozhao123 @ 2024-10-26 22:31:09
@cqxingyun 可以在编译命令行中加入 -Wl,--stack=0x20000000
。
by cqxingyun @ 2024-10-26 22:49:21
对哈