bfs裸题,注意在搜索时为了可以搜索到边缘点,应该在图像的最外一圈加上一圈1
ac代码:
#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int map[961][1441],dir[4][2]={1,0,-1,0,0,1,0,-1},height,weight;
struct node
{
int x, y;
};
int overmap(int x,int y)
{
if(x<0||x>height+1||y<0||y>weight+1) return 1;
else return 0;
}
void bfs(int a,int b)
{
queue<node>q;
node first,next;
first.x=a;
......
阅读全文