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

  1. 3 4 5
  2. 3 2
  3. 2 2
  4. 3 1
  5. 2 3
  6. 1 1

Sample Output

  1. 4

Source

 
原题大意: 给张地图,然后看看最大连通的面积。
解题思路: 快到新生赛了,每天刷两道水题。DFS
 
  1. #include<stdio.h>
  2. int map[120][120],ans,n,m,squ,max;
  3. const int dx[2][4]={{0,0,1,-1},{1,-1,0,0}};
  4. void dfs(int x,int y)
  5. {
  6. int i,xx,yy;
  7. for(i=0;i<4;++i)
  8. {
  9. xx=x+dx[0][i];yy=y+dx[1][i];
  10. if(xx>0&&yy>0&&xx<=n&&yy<=m&&map[xx][yy])
  11. {
  12. map[xx][yy]=0;
  13. ++squ;
  14. dfs(xx,yy);
  15. }
  16. }
  17. return ;
  18. }
  19. int main()
  20. {
  21. int k,i,j;
  22. scanf("%d%d%d",&n,&m,&k);
  23. while(k--)
  24. {
  25. scanf("%d%d",&i,&j);
  26. map[i][j]=1;
  27. }
  28. for(i=1;i<=n;++i)
  29. for(j=1;j<=m;++j)
  30. if(map[i][j])
  31. {
  32. squ=1;
  33. map[i][j]=0;
  34. dfs(i,j);
  35. max=max<squ?squ:max;
  36. }
  37. printf("%d\n",max);
  38. return 0;
  39. }

  

[深度优先搜索] POJ 3620 Avoid The Lakes的更多相关文章

  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

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

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

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

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

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

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

  7. [深度优先搜索] POJ 1426 Find The Multiple

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28550   Accepted: 118 ...

  8. POJ 3009 深度优先搜索

    问题:打冰球.冰球可以往上下左右4个方向走,只有当冰球撞到墙时才会停下来,而墙会消失.当冰球紧贴墙时,不能将冰球往那个方向打.冰球出界就当输,超过10次还没将冰球打到目标位置也当输.求用最小次数将冰球 ...

  9. 深度优先搜索初尝试-DFS-LakeCounting POJ No.2386

    DFS入门的一道经典题目:LakeCounting 用栈或队列来实现: #include<cstdio> #include<stdlib.h> #include<iost ...

随机推荐

  1. 荒废了很久的java以及微信公众平台今天拿起来看了看:这里有很好的教程

    我的微信公众号刚刚起步: ,感兴趣可以关注一下. 关于java开发微信公众号有一个很好的教程博客:推荐一下:http://blog.csdn.net/lyq8479/article/details/8 ...

  2. Oracle建表

    1.oracle数据库中的多种数据结构: 1.表结构            存储数据 2.视图 一张表或多张表中数据的字节 3.sequence 主要用来生成主键值 4.index 提高检索性能 我们 ...

  3. php 5.3新增的闭包语法介绍function() use() {}

    * 下面提到的代码在PHP5.3以上版本运行通过. */function callback($callback) { $callback();}//输出: This is a anonymous fu ...

  4. HTML5滑动(swipe)事件

    移动H5开发中经常用到滑动效果(页面上移.下移.向左滑动.向右滑动等),浏览器并没有内置swipe事件,可以通过touch事件(touchstart.touchmove和touchend)模拟swip ...

  5. 使用 CSS3 绘制 Hello Kitty

    偶然间看到了 SegmentFault 上的一篇文章,感觉这个 Hello Kitty 画的还不错,心血来潮也用 CSS3 画了个 Hello Kitty,现在在这里记录一下详细的绘制过程.想要源码. ...

  6. sql server 查询表结构

    --查询表结构start SELECT 序号 = a.colorder,字段名称 = a.name,字段描述 = f.value, 标识 then '√' else '' end, 主键 FROM s ...

  7. C#文件创建、修改、访问时间修改

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. 【Java】集合_学习笔记

    一.集合 1.集合类也称容器类,主要负责保存.盛装其他数据. 2.集合可以保存数量不确定的数据,保存具有映射关系的数据(也称关联数组). 3.Java5后提供一些多线程安全的集合类,放在java.ut ...

  9. centos6.7 mutlipath install script

    #!/bin/bash if [ `id -g` != 0 ] ;then echo -e "\033[31m Please use root user\033[0m" exit ...

  10. 【转】 linux内存管理

    一 为什么需要使用虚拟内存 大家都知道,进程需要使用的代码和数据都放在内存中,比放在外存中要快很多.问题是内存空间太小了,不能满足进程的需求,而且现在都是多进程,情况更加糟糕.所以提出了虚拟内存,使得 ...