POJ 3620 Avoid The Lakes
来源:互联网 发布:淘宝清洗后钱该怎么办 编辑:程序博客网 时间:2024/05/20 16:13
DFS的应用, 求最大连通分量。刚开始在想要不要从每个格子开始深搜,并不断更新最大值。后来参考了大神的博客之后发现并不需要复原,直接变成0就好。
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int MAXN = 105;int maze[MAXN][MAXN];int dir[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};int ans, cnt, C, R, K;void dfs(int x, int y){if (x < 1 || x > R || y < 1 || y > C || maze[x][y] == 0)return;maze[x][y] = 0;cnt++;for (int i = 0; i < 4; i++)dfs(x + dir[i][0], y + dir[i][1]);}int main(){while (scanf("%d%d%d", &R, &C, &K) != EOF){for (int i = 1; i <= R; i++)for (int j = 1; j <= C; j++)maze[i][j] = 0;while (K--){int i, j;scanf("%d%d", &i, &j);maze[i][j] = 1;}ans = 0;for (int i = 1; i <= R; i++)for (int j = 1; j <= C; j++)if (maze[i][j]){cnt = 0;dfs(i, j);ans = max(cnt, ans);}printf("%d\n", ans);}}
0 0
- poj 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- POJ 3620 Avoid The Lakes
- POJ--3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- POJ 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- POJ 3620 Avoid The Lakes
- poj 3620 Avoid The Lakes
- POJ 3620 Avoid The Lakes
- POJ - 3620-Avoid The Lakes
- POJ 1426 Find The Multiple
- 徒步一千里 (1930) (長津惠山)
- golang---利用反射机制对结构体进行循环赋值
- POJ 2243 Knight Moves
- Sqoop_1. 基本架构及数据操作 -- 待完善
- POJ 3620 Avoid The Lakes
- 【Leetcode】Search a 2D Matrix
- 一些笔记
- 果然还是不够努力是吗?
- 【心灵感悟】—看【人生就是一次列车的旅行】PPT之感
- 八、深拷贝和浅拷贝
- 体力耗费
- VS设置中的MT(d)与MD(d)
- 图结构练习——最短路径