是什么让这段代码过不了测试点 2?
查看原帖
是什么让这段代码过不了测试点 2?
786834
Herman526楼主2023/5/1 09:02

在解决这个问题时,我用了 bfs。

#include<bits/stdc++.h>
bool c[500][500],f[500][500][3];//c 为地图,f[i][j][k] 表示翻越 k 次后到达点 (i,j) 的情况是否记录
char g[750000];//g 为 bfs 的点的翻越次数
short h,w,a[750000],b[750000],x,y,m,n;//a,b 为 bfs 点 x,y 坐标
int s=0,t=1;
void r(int o){
	if(o&&(g[t]=g[s]+c[x][y])^3&&!f[x][y][g[t]])if(x^m||y^n)f[a[t]=x][b[t]=y][g[t]]=1,t++;else puts("YES"),exit(0);
}//判断是否加入队列,^3 即 <3
int main(){
	scanf("%hd%hd",&h,&w);
	for(short i=0;i<h;i++){
		getchar();//我也试过 2 个 getchar 的
		for(short j=0;j<w;j++){
			char _=getchar();
			if(_^35){//# ASCII 码 35
				c[i][j]=0;
				if(_^'s'){if(_^46)m=i,n=j;}//. ASCII 码 46
				else f[a[0]=i][b[g[0]=0]=j][0]=1;
			}
			else c[i][j]=1;
		}
	}
	while(s<t)x=a[s]-1,y=a[t],r(~x),r((x+=2)^h),x--,r(~--y),r((y+=2)^w),f[a[s]][b[s]][g[s]]=0,s++;//bfs
    puts("NO");
}

我不断地交了这段代码,但它总过不了测试点 2。大家知道这段代码错在哪儿了吗?

说实话,这是我第 33 次发这个帖了,所以只要你有帮我调代码的意愿(即使没有调好),也可以回复。

2023/5/1 09:02
加载中...