Avoid The Lakes POJ 3620
来源:互联网 发布:Mac用什么浏览器好 编辑:程序博客网 时间:2024/05/09 21:19
Description
Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of water. His insurance agency will only repay him, however, an amount depending on the size of the largest "lake" on his farm.
The farm is represented as a rectangular grid with N (1 ≤ N ≤ 100) rows and M (1 ≤ M ≤ 100) columns. Each cell in the grid is either dry or submerged, and exactly K (1 ≤ K ≤ N × M) of the cells are submerged. As one would expect, a lake has a central cell to which other cells connect by sharing a long edge (not a corner). Any cell that shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected cell and is part of the lake.
Input
* Line 1: Three space-separated integers: N, M, and K
* Lines 2..K+1: Line i+1 describes one submerged location with two space separated integers that are its row and column: R and C
Output
* Line 1: The number of cells that the largest lake contains.
Sample Input
3 4 5
3 2
2 2
3 1
2 3
1 1
Sample Output
Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of water. His insurance agency will only repay him, however, an amount depending on the size of the largest "lake" on his farm.
The farm is represented as a rectangular grid with N (1 ≤ N ≤ 100) rows and M (1 ≤ M ≤ 100) columns. Each cell in the grid is either dry or submerged, and exactly K (1 ≤ K ≤ N × M) of the cells are submerged. As one would expect, a lake has a central cell to which other cells connect by sharing a long edge (not a corner). Any cell that shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected cell and is part of the lake.
Input
* Line 1: Three space-separated integers: N, M, and K
* Lines 2..K+1: Line i+1 describes one submerged location with two space separated integers that are its row and column: R and C
Output
* Line 1: The number of cells that the largest lake contains.
Sample Input
3 4 5
3 2
2 2
3 1
2 3
1 1
Sample Output
4
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=100+5;int maze[maxn][maxn];int R,C,K;int ans,cnt;int nx[4]={-1,1,0,0};int ny[4]={0,0,-1,1}; void dfs(int r,int c){if(r<1||r>R||c<1||c>C||maze[r][c]==0)return;maze[r][c]=0;cnt++;for(int d=0;d<4;d++)dfs(r+nx[d],c+ny[d]);}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]==1){cnt=0;dfs(i,j);ans=max(ans,cnt);}printf("%d\n",ans);}return 0;}
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
- Java 理论与实践: 流行的原子
- .NET中使用Redis
- HttpURLConnection Handler PULL解析数据 listView 版本更新
- Java中浮点型数据Float和Double进行精确计算的问题
- 【HD 1241】Oil Deposits
- Avoid The Lakes POJ 3620
- DLL注入和API拦截
- Java8引入的lambda表达式
- android 百度地图集成之 导航
- jqGrid点击的行与选中的行不一致的问题
- 关于线程锁定的一道面试题
- JavaScript 刷新/重新加载当前页面
- HTML学习08-_TABLE标签 表格标签
- 变形课 hd 1181