求救大佬,0分,听取WA声一片(必关)
查看原帖
求救大佬,0分,听取WA声一片(必关)
1373509
Himborne楼主2024/11/23 10:39
#include <bits/stdc++.h>
using namespace std;
char Map[110][110];
int n,m,i,j,l[8][2]={{1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}};
bool vis[110][110];
struct node{
	int x,y,step;	
}f,v;
queue<node> q;
int bfs(){
	int t=0;
	f.step=0; 
	q.push(f);
	while(!q.empty()){	
		q.pop();
		t=max(t,f.step);
		for(i=0;i<8;i++){
			v.x=f.x+l[i][0];
			v.y=f.y+l[i][1];
			v.step=f.step+1;
			if(v.x<1||v.x>n||v.y<1||v.y>m){
				continue;
			}
			if(vis[v.x][v.y]==true){
				continue;
			}
			if(Map[v.x][v.y]=='*'){
				continue;
			}
			q.push(v);
			vis[v.x][v.y]=true;
		}
	}	
	return t;
}
int main(){
	cin >> m >> n;
	cin >> f.y >> v.x;
	vis[f.x][f.y]=true;
	for(i=n;i>0;i--){
		for(j=1;j<=m;j++){
			cin >> Map[i][j];
		}
	}
	cout << bfs() << endl;
	return 0;
}

救命啊

2024/11/23 10:39
加载中...