文章
12
粉丝
0
获赞
12
访问
637
#include<bits/stdc++.h>
using namespace std;
int m,n;
const int N = 55;
int a[N][N];
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct node{
int x,y,h;
int step;
};
vector<node> v;
bool func(node a, node b){
return a.h < b.h;
}
int bfs(int start_x,int start_y,int end_x,int end_y){
if(start_x == end_x && start_y == end_y){
return 0;
}
bool visited[55][55] = {false};
queue<node> q;
q.push({start_x,start_y,a[start_x][start_y]});
int step = 0;
visited[start_x][start_y] = 1;
while(!q.empty()){
node temp = q.front();
q.pop();
if(temp.x == end_x && temp.y == end_y)
return temp.step;
for(int i = 0 ; i < 4; i ++){
int nx = temp.x + dx[i];
int ny = temp.y + dy[i];
if(nx >= 0 && nx < m && ny >= 0 && ny < n && a[nx][ny] != 0&&!visited[nx][ny]){
visited[nx][ny] = 1;
q.push({nx,ny,a[nx][ny],temp.step...
登录后发布评论
暂无评论,来抢沙发