当前位置: 代码迷 >> 综合 >> DFS poj3620 Avoid The Lakes
  详细解决方案

DFS poj3620 Avoid The Lakes

热度:62   发布时间:2023-12-14 04:11:58.0

题意:求最大节点的连通块的节点数量


用一个实际参数记录当前连通块里的总数,然后遍历完所有的连通块,找到节点最多的


#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>using namespace std;
typedef long long LL;
typedef pair<int, int> PII;const int MX = 100 + 5;
const int INF = 0x3f3f3f3f;int m, n;
bool S[MX][MX];
int dist[][2] = {
   { -1, 0}, {1, 0}, {0, 1}, {0, -1}};void DFS(int x, int y, int &sum) {S[x][y] = 0;sum++;for(int k = 0; k < 4; k++) {int nx = x + dist[k][0];int ny = y + dist[k][1];if(nx < 1 || nx > m || ny < 1 || ny > n) continue;if(!S[nx][ny]) continue;DFS(nx, ny, sum);}
}int main() {int k;while(~scanf("%d%d%d", &m, &n, &am
  相关解决方案