文章

15

粉丝

142

获赞

25

访问

12.0k

头像
石油储藏 题解:
P1564 中国科学院大学2021年机试题
发布于2023年5月11日 16:37
阅读数 668

#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int, int> PII; // 定义一个二元组类型,用于存储坐标

const int N = 110; // 表示地图大小的最大值

int n, m;
int d[N][N]; // 存储每个点是否被访问过的状态
char g[N][N]; // 存储地图信息
int res = 0; // 记录岛屿数量

void bfs(int s1,int s2){
    queue<PII> q; // 声明一个队列,用于存储每次搜索到的点
    d[s1][s2] = 1; // 将该点标记为已访问
    int dx[8]={-1, 0, 1, 0, -1, 1, 1, -1},dy[8]={0, 1, 0, -1, -1, 1, -1, 1}; // 定义一个数组表示每个点八个方向
    q.push({s1,s2}); // 将起始点加入队列
    while(q.size()){
        auto t = q.front(); // 取出队头元素
        q.pop(); // 弹出队头元素
        for (int i=0;i<8;i++){ // 枚举该点八个方向
            int x = t.first + dx[i];
     &nb...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发