Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

Submit
Status

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 ≤ KN × 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<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int map[1010][1010];
int n,m,s,ans,maxx;
void dfs(int x,int y)
{
if(x<1||x>n||y<1||y>m||map[x][y]==0)
return ;
map[x][y]=0;
ans++;
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y+1);
dfs(x,y-1);
}
int main()
{
while(scanf("%d%d%d",&n,&m,&s)!=EOF)
{
int x,y;
maxx=0;
memset(map,0,sizeof(map));
for(int i=0;i<s;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=1;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(map[i][j])
{
ans=0;
dfs(i,j);
maxx=max(ans,maxx);
}
}
}
printf("%d\n",maxx);
}
return 0;
}

poj--3620--Avoid The Lakes(dfs)的更多相关文章

  1. poj 3620 Avoid The Lakes【简单dfs】

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6795   Accepted: 3622 D ...

  2. POJ 3620 Avoid The Lakes【DFS找联通块】

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6826   Accepted: 3637 D ...

  3. [深度优先搜索] POJ 3620 Avoid The Lakes

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 4270 D ...

  4. POJ 3620 Avoid The Lakes(dfs算法)

    题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j ).求出其中相连的被淹没的农田的最大范围. 思路:dfs算法 代码: #include<iostream> #inc ...

  5. POJ 3620 Avoid The Lakes (求连接最长的线)(DFS)

    Description Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the i ...

  6. POJ 3620 Avoid The Lakes

    http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...

  7. poj 3620 Avoid The Lakes(广搜,简单)

    题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...

  8. Avoid The Lakes

    Avoid The Lakes Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

  9. POJ 1321-棋盘问题(DFS 递归)

    POJ 1321-棋盘问题 K - DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I6 ...

随机推荐

  1. [Javascirpt] Developer-friendly Flow Charts with flowchart.js

    Flowchart.js is a great tool for creating quick, simple flowcharts in a way that keeps you out of a ...

  2. 取消记录tableView选中效果

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self. ...

  3. poj 2777 Count Color(线段树、状态压缩、位运算)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38921   Accepted: 11696 Des ...

  4. EditText电话号码格式化输入、删除案例

    我们在输入电话号码的时候,一般都会切割一个较长的电话号码.这种话效果会好非常多..对EditText的监听能够轻松的实现这个需求.仅仅须要我们给相应的EditText加一个监听就OK了..贴一下我写的 ...

  5. 创建ios界面的三步骤

    1.加载数据 (包括懒加载和字典转模型等) 2.搭建界面 (常见的有九宫格算法和for循环的嵌套等) 3.实现用户交互 (通常用按钮实现)

  6. BZOJ 2096 单调队列

    思路: 偷懒用的STL //By SiriusRen #include <deque> #include <cstdio> using namespace std; struc ...

  7. AOJ 0118: Property Distribution (简单DFS)

    题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0118 题意:给定一个矩阵,同类字符相连的为一个块,问总共有几个块. 输入 ...

  8. 自定义pulltoRefresh的刷新和加载动画

    一:定义刷新动画的layout 共同的设置方法是 1:getDefaultDrawableResId() 2:refreshingImpl() 正在刷新时的回调方法,可以设置开始动画 3:resetI ...

  9. Mysql数据库批量添加数据

    1.目的: 用于向Mysql表中批量插入数据 2.过程: 3.语句 #删除已有存储过程 DROP PROCEDURE if exists insertdata; #设定命令行出现//后再执行语句 de ...

  10. MySQL用户添加和分配权限

    mysql数据库insertdelete服务器file mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口 ...