Lake Counting
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 41340 | Accepted: 20504 |
Description
Given a diagram of Farmer John's field, determine how many ponds he has.
Input
* Lines 2..N+1: M characters per line representing one row of Farmer John's field. Each character is either 'W' or '.'. The characters do not have spaces between them.
Output
Sample Input
10 12
W........WW.
.WWW.....WWW
....WW...WW.
.........WW.
.........W..
..W......W..
.W.W.....WW.
W.W.W.....W.
.W.W......W.
..W.......W.
Sample Output
3
Hint
There are three ponds: one in the upper left, one in the lower left,and one along the right side.
Source
#include<iostream>
using namespace std;
char field[][];
int n, m;
void dfs(int i, int j)
{
field[i][j] = '.';
for(int dx=-;dx<=;dx++)
for (int dy = -; dy <= ; dy++)
{
int k = i + dx, kk = j + dy;
if (k >= && k < n&& kk < m&&kk >= && field[k][kk] == 'W')
dfs(k, kk);
}
return;
}
int main()
{
int mark = ;
cin >> n >> m;
for (int i = ; i < n; i++)
for (int j = ; j < m; j++)
cin >> field[i][j];
for(int i=;i<n;i++)
for (int j = ; j < m; j++)
if (field[i][j] == 'W')
{
dfs(i, j);
mark++;
}
cout << mark << endl;
return ;
}
真正意义上的第一个深度题,代码不是很难理解,可是感觉掌握起来有点小麻烦;
还需多练习
Lake Counting的更多相关文章
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
- POJ 2386 Lake Counting(深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17917 Accepted: 906 ...
- POJ 2386 Lake Counting
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28966 Accepted: 14505 D ...
- bzoj1751 [Usaco2005 qua]Lake Counting
1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec Memory Limit: 64 MB Submit: 168 Solved: 130 [ ...
- BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘
题目 3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MB Description 农夫 ...
- 3385: [Usaco2004 Nov]Lake Counting 数池塘
3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 22 Solved: 21 ...
- 1751: [Usaco2005 qua]Lake Counting
1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 190 Solved: 150[Su ...
- 洛谷 P1596 [USACO10OCT]湖计数Lake Counting
题目链接 https://www.luogu.org/problemnew/show/P1596 题目描述 Due to recent rains, water has pooled in vario ...
- Poj2386 Lake Counting (DFS)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 49414 Accepted: 24273 D ...
- [POJ 2386] Lake Counting(DFS)
Lake Counting Description Due to recent rains, water has pooled in various places in Farmer John's f ...
随机推荐
- 类中定义的方法,self参数
class a(): def __init__(self): self.aa = 5 def test(): print "haha" a.test() self指的是对象本身,而 ...
- mysql案例~关于linux服务器本身的优化问题
简介:mysql服务优化分为 1服务器本身的优化 2mysql本身的性能优化 今天咱们来讨论下服务器本身的优化性能 一 参数的优化简介 1 文件系统的选择 Linux 常用文件系统: ext3, ex ...
- 深度学习——深度神经网络(DNN)反向传播算法
深度神经网络(Deep Neural Networks,简称DNN)是深度学习的基础. 回顾监督学习的一般性问题.假设我们有$m$个训练样本$\{(x_1, y_1), (x_2, y_2), …, ...
- 接口转换 数据库列表的内容 显示在datagrid
public class AddressConverter : IValueConverter { public object Convert(object value, Type targetTyp ...
- python答题辅助
最近直播答题app很热门,由于之前看过跳一跳的python脚本(非常棒),于是也想写一个答题的脚本. https://github.com/huanmsf/cai 思路: 1.截图 2.文字识别,提取 ...
- NOIP2018 20天训练
Day 0 2018.10.20 其实写的时候已经是Day 1了--(凌晨两点) 终于停课了,爽啊 get树状数组+线段树(延迟标记) 洛谷:提高组所有nlogn模板+每日一道搜索题(基本的图的遍历题 ...
- C++ Template 编程,泛型编程练习
#include <iostream> #include <string> #include <deque> #include <stdexcept> ...
- Go语言中的slice
Go语言中的slice有点类似于Java中的ArrayList,但在使用上更加灵活,先通过下面一个小例子来体验一下如何通过一个已有的切片来产生一个新切片: func main() { slice := ...
- VS2015 代码片段整理
1.什么是代码段? 将一段代码行提取出来,可以多次重复的使用.VS IDE提供对代码段的完整支持.使代码编写更快.更容易.更可靠. 2.系统默认代码段 对于开发人员的例行任务,Visual Studi ...
- hibernate框架学习之数据查询(HQL)helloworld
package cn.itcast.h3.hql; import java.util.List; import org.hibernate.Query; import org.hibernate.Se ...