Avoid The Lakes
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7023   Accepted: 3735

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<cstring>
#include<algorithm>
using namespace std;
int N,K,M,a,b,cot,best;
int map[][];
int mov[][]={,,,-,,,-,};
bool can(int x,int y)/判断能否符合条件
{
if(x<||x>=N||y<||y>=K||!map[x][y])
return false;
return true;
}
void dfs(int x,int y)//深搜
{
int xx,yy,i;
map[x][y]=;//标记走过
for(i=;i<;i++)
{
xx=x+mov[i][];
yy=y+mov[i][];
if(can(xx,yy))
{
cot++;
dfs(xx,yy);
}
}
}
int main()
{
int i,j;
while(scanf("%d%d%d",&N,&K,&M)!=EOF)
{
memset(map,,sizeof(map));
for(i=;i<M;i++)
{
scanf("%d%d",&a,&b);
map[a-][b-]=;
}
int sum=;
best=;
for(i=;i<N;i++)
for(j=;j<K;j++)
{
cot=;
if(map[i][j])
{
dfs(i,j);
}
best=best>cot?best:cot;//更新最优解
}
printf("%d\n",best);
}
return ;
}
												

Avoid The Lakes--poj3620的更多相关文章

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

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

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

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

  3. Avoid The Lakes

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

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

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

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

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

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

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

  7. 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 ...

  8. POJ 3620 Avoid The Lakes

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

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

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

随机推荐

  1. dojo Tree 添加、删除节点

    var tree=this.tree; var store=tree.model.store; if(this.node){ console.log(this.node) var children=t ...

  2. MySQL--连接属性

    The capability flags are used by the client and server to indicate which features they support and w ...

  3. abiword Namespace List

    abiword Namespace List Here is a list of all namespaces with brief descriptions: abicollab  这个命名空间以及 ...

  4. Java 学习 第一篇

    1:Java文档注释:使用javadoc工具可以提取程序中文档注释来生成API文档:javadoc命令的基本用法:javadoc 选项 java源文件/包javadoc -d {} -windowti ...

  5. 【其他】IT公司的企业文化与竞争力

    一直觉得三流企业靠成本竞争,二流企业靠体制竞争,一流企业靠文化竞争. 企业在竞争时候,总会提到一个词:核心竞争力.对于IT企业来说,核心竞争是什么?无论是技术也好,销售也罢,归根到底还是人才的竞争,优 ...

  6. mosquitto在Linux环境下的部署/安装/使用/测试

    mosquitto在Linux环境下的部署 看了有三四天的的源码,(当然没怎么好好看了),突然发现对mosquitto的源码有了一点点感觉,于是在第五天决定在Linux环境下部署mosquitto. ...

  7. ubuntu 12.04(Precise Pangolin)启用休眠(Hibernate)功能的方案

    官方支持文档:https://help.ubuntu.com/12.04/ubuntu-help/power-hibernate.html 按照这篇官方支持,因为休眠功能存在bug,12.04没有默认 ...

  8. FZU 1856 The Troop (JAVA高精度)

    Problem 1856 The Troop Accept: 72    Submit: 245Time Limit: 1000 mSec    Memory Limit : 32768 KB Pro ...

  9. myeclipse修改tomcat端口

    myeclipse自带的tomcat可以直接在myeclipse下面进行配置,但是如果是配置的tomcat 只能自己手动修改了

  10. jQuery支持移动Mobile的DOM元素移动和缩放插件

    jQuery Panzoom是一款很有用的HTML DOM元素平移和缩放jQuery和CSS3插件. Panzoom利用CSS transforms 和 matrix函数来为浏览器进行硬件(GPU)加 ...