poj 3620 Avoid The Lakes
来源:互联网 发布:圆形水池计算软件 编辑:程序博客网 时间:2024/05/18 22:45
很简单的dfs
/*Poj: 3620 Avoid The Lakes*/#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#define MaxN 105using namespace std;int dirx[4] = {0, 0, -1, 1};int diry[4] = {-1, 1, 0, 0};bool map[MaxN][MaxN];bool visited[MaxN][MaxN];;int n, m, k;bool check(int x, int y){ if(x >= 1 && x <= n && y >= 1 && y <= m) return true; return false;}int dfs(int x, int y){ int total = 1; for(int i = 0; i < 4; i++) { int tmpx = x + dirx[i]; int tmpy = y + diry[i]; if(check(tmpx, tmpy) && !visited[tmpx][tmpy] && map[tmpx][tmpy]) { visited[tmpx][tmpy] = true; total += dfs(tmpx, tmpy); } } return total;}int main(){ //freopen("data.in", "rb", stdin); while(scanf("%d%d%d", &n, &m, &k) != EOF) { memset(map, false, sizeof(map)); for(int i = 0; i < k; i++) { int a, b; scanf("%d%d", &a, &b); map[a][b] = true; } memset(visited, false, sizeof(visited)); int res = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(!visited[i][j] && map[i][j]) { visited[i][j] = true; res = max(dfs(i, j), res); } } } printf("%d\n", res); } return 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
- F - Babelfish解题报告
- (实验一) --- 彩色图像变换成灰度图像---matlab实现
- 冒泡排序
- 随笔-能够让我们感觉美好的只是回忆而已
- 0/1背包问题
- poj 3620 Avoid The Lakes
- linux块设备6
- 13.2
- poj 3614 Sunscreen
- 安意如美丽的句子
- 线程池ThreadPoolExecutor参数设置
- Posix线程编程指南(1)
- OpenCV-我的开始
- WIN7 X64 GDAL GEOS 编译