题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j )。求出其中相连的被淹没的农田的最大范围。

思路:dfs算法

代码:

#include<iostream>
#include<stdio.h>
using namespace std;
int t[150][150];
int visit[150][150];
int n,m,k;
int dfs(int i,int j){
if(i<1||j<1||i>n||j>m||t[i][j]==0||visit[i][j]==1)
return 0;
visit[i][j]=1;
int sum=1;
sum=sum+dfs(i-1,j);
sum=sum+dfs(i+1,j);
sum=sum+dfs(i,j-1);
sum=sum+dfs(i,j+1);
return sum;
}
int main(){
scanf("%d%d%d",&n,&m,&k);
int i,j;
int max=0;
int sum;
while(k--){
scanf("%d%d",&i,&j);
t[i][j]=1;
}
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(t[i][j]==1&&visit[i][j]==0){
sum=dfs(i,j);
if(sum>max)
max=sum;
}
printf("%d\n",max);
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)

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

  5. POJ 3620 Avoid The Lakes

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

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

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

  7. Avoid The Lakes

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

  8. poj--3620--Avoid The Lakes(dfs)

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Subm ...

  9. BFS/DFS算法介绍与实现(转)

    广度优先搜索(Breadth-First-Search)和深度优先搜索(Deep-First-Search)是搜索策略中最经常用到的两种方法,特别常用于图的搜索.其中有很多的算法都用到了这两种思想,比 ...

随机推荐

  1. 【Python】matplotlib绘制折线图

    一.绘制简单的折线图 import matplotlib.pyplot as plt squares=[1,4,9,16,25] plt.plot(squares) plt.show() 我们首先导入 ...

  2. jquery Table基础操作

    鼠标移动行变色     $("#table1 tr").hover(function(){          $(this).children("td").ad ...

  3. python for android : BeautifulSoup 有 bug

    BeautifulSoup 善于网页数据分析 .可是 python for android : BeautifulSoup 有 bug , text = h4.a.text 仅仅能取得 None,因此 ...

  4. IOS中公布应用程序,进度条一直不走怎么处理

    在IOS中公布应用程序非常是喜闻乐见. 近期1周.我更新了6次版本号.可是时不时的会卡住,进度条不走. 最后总结了几个原因. 1.在公布前你要确认自己的证书是否配置正确 2.DNS域名server有没 ...

  5. 深度 | Facebook的图像识别很强大,一次开源了三款机器视觉工具(附论文)

    http://mp.weixin.qq.com/s?__biz=MzA3MzI4MjgzMw==&mid=2650718597&idx=1&sn=56aa4e5deff9962 ...

  6. 可执行Jar包调用动态链接库(DLL/SO)

    踩过了很多的坑,查了很多资料,在此记录一下,以SpringBoot项目为基础. Maven加入JNA依赖 <!-- JNA start --> <dependency> < ...

  7. easyUI中 datagrid 格式化日期

    $('#List').datagrid({ url: '@Url.Action("GetList")', width:SetGridWidthSub(10), methord: ' ...

  8. 15 redis 之 aof恢复与rdb服务器间迁移

    三:常见的问题 BGREWRITEAOF 后台进程重写AOF BGSAVE 后台保存rdb快照 SAVE 保存rdb快照 LASTSAVE 上次保存时间 Slaveof master-Host por ...

  9. HDOJ 题目3564 Another LIS(线段树单点更新,LIS)

    Another LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  10. Mac 下 Git 的基础命令行操作

    Mac 下 Git 的基础命令行操作 sudo apt-get install git-core //安装Git 用户配置 git config --global user.name "Yo ...