DFS:Lake Counting(POJ 2386)
好吧前几天一直没更新博客,主要是更新博客的确是要耗费一点精力
最近更新博客可能就是一点旧的东西和一些水题,主要是最近对汇编感兴趣了嘻嘻嘻
这一题挺简单的,没什么难度,简单深搜
#include <stdio.h>
#include <stdlib.h> typedef int Postion; static int Lake[][];
static int N, M; void DFS(Postion, Postion); int main(void)
{
int i, j, pool = ;
while (~scanf("%d%d",&N,&M))
{
for (i = ; i < N; i++)//读图
{
getchar();//别忘了现在是输入的是字符,一定要把回车键拿掉
for (j = ; j < M; j++)
scanf("%c", &Lake[i][j]);
} for (i = ; i < N; i++)
for (j = ; j < M; j++)
if (Lake[i][j] == 'W')
{
DFS(i, j);
pool++;
}
printf("%d\n", pool);
}
} void DFS(Postion x, Postion y)
{
int i, j;
Postion toi, toj;
Lake[x][y] = '.';//搜索过的地方就置换成. for (i = -; i <= ; i++)
for (j = -; j <= ; j++)
{
toi = x + i; toj = y + j;
if (toi >= && toi < N
&& toj >= && toj < M//坐标均在图内
&& Lake[toi][toj] == 'W'//且没进入搜索过
)
DFS(toi, toj);
}
}
DFS:Lake Counting(POJ 2386)的更多相关文章
- POJ 2386 Lake Counting(深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17917 Accepted: 906 ...
- Lake Counting(POJ No.2386)
题目描述:有一个大小为N*M的园子,八连通的积水被认为是连接在一起的.请求出园子里总共有多少水洼?(八连通指的是下图中相对w的*部分) *** *w* *** 限制条件 N,M<=100 样例 ...
- poj-2386 lake counting(搜索题)
Time limit1000 ms Memory limit65536 kB Due to recent rains, water has pooled in various places in Fa ...
- 图的DFS和BFS(邻接表)
用C++实现图的DFS和BFS(邻接表) 概述 图的储存方式有邻接矩阵和邻接表储存两种.由于邻接表的实现需要用到抽象数据结构里的链表,故稍微麻烦一些.C++自带的STL可以方便的实现List,使算 ...
- POJ:2386 Lake Counting(dfs)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40370 Accepted: 20015 D ...
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
- 【POJ - 2386】Lake Counting (dfs+染色)
-->Lake Counting 直接上中文了 Descriptions: 由于近日阴雨连天,约翰的农场中中积水汇聚成一个个不同的池塘,农场可以用 N x M (1 <= N <= ...
- POJ 2386 Lake Counting(搜索联通块)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48370 Accepted: 23775 Descr ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
随机推荐
- 【POJ 1416】Shredding Company
题 题意 给你一个target number,和一个最多六位的数num,让你把数分段,使总和最接近但不大于target number. 如果只有一种方法就输出总和.分段,如果有多种方法,输出rejec ...
- 超级懒汉编写的基于.NET的微信SDK
一.前言 特别不喜欢麻烦的一个人,最近碰到了微信开发.下载下来了一些其他人写的微信开发“框架”,但是被恶心到了,实现的太臃肿啦. 最不喜欢的就是把微信返回的xml消息在组装成实体类,所以会比较臃肿,现 ...
- codeforce626C.Block Towers(二分)
C. Block Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- JavaScript的apply和call方法及其区别
参考资料: http://blog.csdn.net/myhahaxiao/article/details/6952321 apply和call能“劫持”其他对象的方法来执行,其形参如下: apply ...
- 锋利的jQuery-3--.css()获取和设置元素的数字属性
$('p').css({"fontSize": "30px", "backgroundColor": "#666"}); ...
- Visual Studio Online Integrations-Build and release
原文:http://www.visualstudio.com/zh-cn/explore/vso-integrations-dire ...
- WCF报 当前已禁用此服务的元数据发布的错误
这是 Windows© Communication Foundation 服务. 当前已禁用此服务的元数据发布. 如果具有该服务的访问权限,则可以通过完成下列步骤来修改 Web 或应用程序配置文件以便 ...
- linux 查找php.ini 文件
sudo find /* -name 'php.ini' /etc/php5/fpm/php.ini
- CentOS6.5安装iftop
iftop这个小工具是Linux和unix下的top命令升级版,功能相对较强,界面易懂.今天安装了CentOS6.5的最新版,装个小工具检查下系统运行性能. 官网:http://www.ex-parr ...
- 《深入PHP与jQuery开发》读书笔记——Chapter3
<深入PHP与jQuery开发>第三章学习笔记 1.PHP的魔术方法(在对象中发生某些例行事件时会自动调用这些方法) PHP提供了魔术方法__construct()(构造函数),在新对象被 ...