[深度优先搜索] POJ 3620 Avoid The Lakes
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8173 | Accepted: 4270 |
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
4
Source
#include<stdio.h>
int map[120][120],ans,n,m,squ,max;
const int dx[2][4]={{0,0,1,-1},{1,-1,0,0}};
void dfs(int x,int y)
{
int i,xx,yy;
for(i=0;i<4;++i)
{
xx=x+dx[0][i];yy=y+dx[1][i];
if(xx>0&&yy>0&&xx<=n&&yy<=m&&map[xx][yy])
{
map[xx][yy]=0;
++squ;
dfs(xx,yy);
}
}
return ;
}
int main()
{
int k,i,j;
scanf("%d%d%d",&n,&m,&k);
while(k--)
{
scanf("%d%d",&i,&j);
map[i][j]=1;
}
for(i=1;i<=n;++i)
for(j=1;j<=m;++j)
if(map[i][j])
{
squ=1;
map[i][j]=0;
dfs(i,j);
max=max<squ?squ:max;
}
printf("%d\n",max);
return 0;
}
[深度优先搜索] POJ 3620 Avoid The Lakes的更多相关文章
- poj 3620 Avoid The Lakes【简单dfs】
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6795 Accepted: 3622 D ...
- POJ 3620 Avoid The Lakes【DFS找联通块】
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6826 Accepted: 3637 D ...
- POJ 3620 Avoid The Lakes
http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...
- poj 3620 Avoid The Lakes(广搜,简单)
题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...
- POJ 3620 Avoid The Lakes(dfs算法)
题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j ).求出其中相连的被淹没的农田的最大范围. 思路:dfs算法 代码: #include<iostream> #inc ...
- 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 ...
- [深度优先搜索] POJ 1426 Find The Multiple
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28550 Accepted: 118 ...
- POJ 3009 深度优先搜索
问题:打冰球.冰球可以往上下左右4个方向走,只有当冰球撞到墙时才会停下来,而墙会消失.当冰球紧贴墙时,不能将冰球往那个方向打.冰球出界就当输,超过10次还没将冰球打到目标位置也当输.求用最小次数将冰球 ...
- 深度优先搜索初尝试-DFS-LakeCounting POJ No.2386
DFS入门的一道经典题目:LakeCounting 用栈或队列来实现: #include<cstdio> #include<stdlib.h> #include<iost ...
随机推荐
- WebForm session,cookies
session : Session:在计算机中,尤其是在网络应用中,称为"会话控制".Session 对象存储特定用户会话所需的属性及配置信息.这样,当用户在应用程序的 Web页之 ...
- 【转】封装Lua for C#
原文:http://blog.csdn.net/rcfalcon/article/details/5583095 为了搞懂LUA在我们的GDEX中到底怎么用,我决定研究一下如何比较好的在WPF里封装一 ...
- Python的SublimeText开发环境配置
1.完成Python的默认安装之后要设置环境变量,系统环境变量Path中加入Python的安装目录";C:/Python27" 2.配置Python编译环境,修改[C:\Progr ...
- Arduino入门笔记【1】
刚刚接触这个东西只知道这是类似于单片机的开发板,可以做一些单片机实现或者不能实现的东西,但是比单片机要简单得多. Arduino到底是什么? 维基百科上的描述是:Arduino是一块开发板的微控制器和 ...
- iis设置asp站点
在 IIS 6.0 中,默认设置是特别严格和安全的,这样可以最大限度地减少因以前太宽松的超时和限制而造成的攻击.譬如说默认配置数据库属性实施的最大 ASP 张贴大小为 204,800 个字节,并将各个 ...
- AWT编程学习01(未完成)
本文资料来源:<java疯狂讲义> 作者:李刚 终于要学习这一部分了~~虽然很多人(明明是绝大多数的人)说学这个没有用...而且有点过时了...但我觉得很有意思啊...感兴趣就学~~反正多 ...
- 转!!java事务的处理
java的事务处理,如果对数据库进行多次操作,每一次的执行或步骤都是一个事务.如果数据库操作在某一步没有执行或出现异常而导致事务失败,这样有的事务被执行有的就没有被执行,从而就有了事务的回滚,取消先前 ...
- Python_Day4_函数
本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数 定义: 函数是指将一组语句的集合通过一个名字( ...
- 后台接收URL地址的参数
其实很简单,只是写一下加强记忆 后台接收URL传递过来的参数有两种方法: 第一种用request接收 HttpServletRequest request = ServletActionContext ...
- java:同步和死锁
多个线程共享一个资源的时候需要进行同步(否则会出现错误:如负数,重复数),但是过多的同步会造成死锁. synchronized(this) { } 非同步情况: public class SyncTh ...