Advertisement

AcWing 1097池塘计数题解(BFS-连通块-FloodFill)

阅读量:

AcWing 1097 池塘计数
有关连通块的处理问题,Flood Fill(洪水填充)算法是一种非常典型的广度优先搜索应用,只要在实现过程中注重相关细节即可顺利解决。

复制代码
    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1010;
    
    #define x first
    #define y second
    
    typedef pair<int, int>PII;
    
    int n, m;
    int ans;
    PII q[N * N];
    char g[N][N];
    bool st[N][N];
    
    void bfs(int sx, int sy){
    	st[sx][sy] = true;
    	int hh = 0, tt = 0;
    	q[0] = {sx, sy};
    	
    	while(hh <= tt){
    		PII t = q[hh ++ ];
    		for(int i = t.x - 1; i <= t.x + 1; i ++

全部评论 (0)

还没有任何评论哟~