文章

11

粉丝

318

获赞

6

访问

101.1k

头像
bfs搜索模板题,求联通块的个数
P1564 中国科学院大学2021年机试题
发布于2020年4月16日 00:08
阅读数 6.9k

#include <bits/stdc++.h>
using namespace std;
const int N=105;
bool vis[N][N];
char mp[N][N];
int n,m,dir[][2]={1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,-1,-1,1};
struct node{
   int x,y;
};
void bfs(int x,int y)
{
    vis[x][y]=1;
    queue<node> q;
    q.push({x,y});
    while(q.size())
    {
        node now=q.front();q.pop();
        for(int i=0;i<8;i++)
        {
            int xx=now.x+dir[i][0],yy=now.y+dir[i][1];
            if(xx>=0&&xx<n&&yy>=0&&yy<m&&!vis[xx][yy]&&mp[xx][yy]=='@')
            {
                vis[xx][yy]=1;
                q.push({xx,yy});
            }...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发