poj 3620 Avoid The Lakes
来源:互联网 发布:电气工程制图软件 编辑:程序博客网 时间:2024/05/17 13:41
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 53 22 23 12 31 1
Sample Output
4
#include<stdio.h>#include<string.h>int map[150][150];int dre[4][2]={-1,0,1,0,0,-1,0,1};int n,m,num;void dfs(int x,int y){if(x>=1&&y>=1&&x<=n&&y<=m&&map[x][y]){num++;map[x][y]=0;for(int i=0;i<4;i++){int g=x+dre[i][0];int v=y+dre[i][1];dfs(g,v);}}}int main(){int i,j,k,a,b;while(~scanf("%d%d%d",&n,&m,&k)){//scanf("%d%d%d",&n,&m,&k);memset(map,0,sizeof(map));for(i=0;i<k;i++){scanf("%d%d",&a,&b);map[a][b]=1;}int max=-1;for(i=1;i<=n;i++)for(j=1;j<=m;j++){num=0;dfs(i,j);if(max<num) max=num;}printf("%d\n",max);}}
3 12 31 1Sample Output4
- 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
- Construct Binary Tree from Inorder and Postorder Traversal
- CircleImageView圆形图控件+MPAndroidChart图表控件
- Android java 中如何优雅的结束线程
- LeetCode237——Delete Node in a Linked List
- Android基础之横竖屏切换时Activity的生命周期
- poj 3620 Avoid The Lakes
- Heap Spray原理浅析
- 给定入栈顺序,求解出栈顺序
- 南邮 OJ 1199 B_Conversions
- linux上ln命令详细说明
- Json数据的解析
- Android学习笔记——HelloWorld
- Android Download机制详解
- JavaScript自增、自减运算符与表达式语法