文章
15
粉丝
0
获赞
25
访问
1.9k
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000;
typedef struct node{
int x,y;//坐标
int step;//步数
}node;
char s[maxn][maxn] ={'#'};//高和宽
int visited[maxn][maxn] = {0};//1表示访问过
int yidong[4][2] = {-1,0,1,0,0,-1,0,1};//上下左右移动
int bfs(int x,int y,int l,int t){//l是安全地方个数 t是时间
memset(visited,0, sizeof(visited));
queue<node> q;
// node start ;
// start.x = x;
// start.y = y;
// start.step =0;
// q.push(start);//起点入队
q.push(node{x,y,0});
visited[x][y] =1;
while(!q.empty()){
node n = q.front();
q.pop();
// printf("%d %d %d %d\n",n.x,n.y,n.step,l);
if(n.step > t){
return 1;
}
if(l<0) return -1;
s[n.x][n.y] = '#';
l--;
if(l==0&&q.empty()) {
return 1;
}
//不是终点,则继续移动
for(int i = 0;i<4;i++){
for(int j = 0;j<2;j++){
node next ;
next.x = n.x + yidong[i][0];
next.y = n.y + yidong[i][1];
if(visited[next.x][next.y]==0&&s[nex...
登录后发布评论
输出格式改一下,因为每一行不一定有m列