文章

37

粉丝

68

获赞

6

访问

7.0k

头像
1308 逃离迷宫2
综合
发布于2024年3月12日 16:48
阅读数 250

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

#define inf 0x3f3f3f3f
#define maxn  110
struct node {
    int x, y;
};
int n, m;
node p[4];
char mpt[maxn][maxn];
int vis[maxn][maxn][4];//vis分别代表每个人到每一个点需要消掉的障碍物
int dir[4][2] = { 1, 0, -1, 0, 0, 1, 0, -1 };

void bfs(int index)
{
    queue<node> q;
    node now, next;
    now.x = p[index].x;
    now.y = p[index].y;
    q.push(now);
    vis[now.x][now.y][index] = 0;
    while (!q.empty()) {
        now = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            next = now;
            next.x += dir[i][0];
            next.y += dir[i][1];
            if (next.x<1 || next.x>n || next.y<1 || next.y>m) continue;
            int tmp = vis[now.x][now.y][index];
            if (mpt[next.x][next.y] == '#')tmp++;//遇到一个障碍物,那么此人到达这个点需要消掉的障碍物加1
            if (tmp < vis[next.x][next.y][index]) {...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发