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: NM, 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<string.h>
int dx[]={-,,,};
int dy[]={,,-,};
int n,m,map[][],x,y,i,max,ans,k,j;
void f(int x,int y)
{
int i,nx,ny;
for(i = ; i < ; i++)
{
nx=x+dx[i];
ny=y+dy[i];
if(nx > && ny > && nx <= n && ny <=m && map[nx][ny] == )
{
ans++;
map[nx][ny]=;
f(nx,ny);
}
}
}
int main()
{
while(scanf("%d %d %d",&n,&m,&k)!=EOF)
{
max=;
memset(map,,sizeof(map));
for(i = ; i < k ; i++)
{
scanf("%d %d",&x,&y);
map[x][y]=; //1表示没走过
}
for(i = ; i <=n ; i++)
{
for(j = ; j <= m ; j++)
{ if(map[i][j] == )
{
ans=;
map[i][j]=;
f(i,j);
max=max>ans?max:ans;
} } }
printf("%d\n",max);
}
}

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

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

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

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

  4. POJ 3620 Avoid The Lakes

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

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

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

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

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

  7. poj 1523Tarjan算法的含义——求取割点可以分出的连通分量的个数

    poj 1523Tarjan算法的含义——求取割点可以分出的连通分量的个数 题目大意:如题目所示 给你一些关系图——连通图,想要问你有没有个节点,损坏后,可以生成几个互相独立的网络(也就是连通分量), ...

  8. Avoid The Lakes

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

  9. DFS:POJ3620-Avoid The Lakes(求最基本的联通块)

    Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Description Farmer John's farm was flooded i ...

随机推荐

  1. day04 TimeZone类

  2. Python标准库 re

    正则表达式 regular expression 用来匹配一系列符合句法规则的字符串,是一门独立的小型的语言,如果你了解类Unix系统,那么你对正则表达式就一定不陌生.正则表达式的概念最初是由Unix ...

  3. Codeforces 1108F(克鲁斯卡尔的理解)

    最小生成树会多样的情况是:两个或多个边等长且连通同样的两个并查集块. 所以可以跑一遍克鲁斯卡尔,每次把当前等长的边数出来,注意不要边找边并查,因为有一部分边是正常跑生成树我们也不会要他的,这种直接跳了 ...

  4. [转]EntityFramework之领域驱动设计实践

    本文转自:http://www.cnblogs.com/daxnet/archive/2010/11/02/1867392.html Entity Framework之领域驱动设计实践 EntityF ...

  5. 最新版kubernetesV1.14.1集群一键自动部署脚本

    部署命令如下:详情及注意事项请看README.md git clone https://github.com/luckman666/deploy_Kubernetes-v1.14.1.git cd d ...

  6. Scrapy-Redis分布式爬虫小白问题记录

    1.首先我是将Redis装在了阿里云的一台CentOS6.8上,使用ps -ef|grep redis查看是否成功运行 2.CentOS安装scrapy请参考 http://blog.csdn.net ...

  7. rabbitmq的知识点

    rabbitmq,分为集群和主从2种. 主从式与集群式的速度差10倍. 每个rabittmq组需要3台机器. 集群式,稳定性高,主从式,速度快. 可以做任务分配,单点锁(二进制树实现). 只有当消息和 ...

  8. nginx 访问localhost老是下载文件不能打开网页什么情况?

    nginx打开网页直接下载文件的问题 nginx sites-available文件里的default已经修改过root 路径了. 但是访问localhost的时候总是直接下载网页而不是打开网址 很奇 ...

  9. 一行命令杀掉defunct进程

    一行命令杀掉defunct进程 今天在杀掉defunc过程中一直搞不完,索性写一行命令,注意先看懂谨慎使用 ps -ef|grep defunct|awk '{print " ps -ef| ...

  10. mysql查询-从表1中查询出来的结果重新插入到表1

    原有表结构 CREATE TABLE `t_card_user` ( `id` varchar(32) NOT NULL, `card_user_id` bigint(20) DEFAULT NULL ...