本地可以,洛谷RE,求救
查看原帖
本地可以,洛谷RE,求救
648996
_orange_楼主2023/1/6 22:02
#include<bits/stdc++.h>
using namespace std;
struct node{
	int x;
	int y;
};
char mp[501][501];
bool vis[501][501];
//
//
queue<node>q;
int n,m,sx,sy;
int main(){
	memset(vis,true,sizeof(vis));
	scanf("%d%d",&n,&m);
	getchar();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			vis[i][j]=false;
			mp[i][j]=getchar();
			if(mp[i][j]=='s'){sx=i,sy=j;}
		}
		getchar();
	}
	q.push(node{sx,sy});
	while(!q.empty()){
		node nw=q.front();q.pop();
		if(mp[nw.x][nw.y]=='g'){
			printf("Yes");
			return 0;
		}
		if(mp[nw.x][nw.y]=='#')continue;
		if(!vis[nw.x][nw.y+1]){
			vis[nw.x][nw.y+1]=true;
			q.push(node{nw.x,nw.y+1});
		}
		if(!vis[nw.x+1][nw.y]){
			vis[nw.x+1][nw.y]=true;
			q.push(node{nw.x+1,nw.y});
		}
		if(!vis[nw.x][nw.y-1]){
			vis[nw.x][nw.y-1]=true;
		    q.push(node{nw.x,nw.y-1});
		}
		if(!vis[nw.x-1][nw.y]){
			vis[nw.x-1][nw.y]=true;
			q.push(node{nw.x-1,nw.y});
		}
	}
	printf("No");
	return 0;
}

到底哪些错了,本人蒟蒻求点播谢谢

2023/1/6 22:02
加载中...