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 ...
随机推荐
- 基于Django框架对MongoDB实现增删改查
在上一篇中,咱们已经实现了Scrapy框架爬取数据,并且存储到Mongodb数据库, 接下来呢,,,,,,,,,,,,, 咱们就要对这些数据进行操作. 目标:从Mongodb数据库取出数据,通过Dja ...
- 解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 问题
通过这里的回答,我们可以知道: Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证. 具体来说,就是添加了些规则去限制HTTP头的规范性 参考这里 具体来说 ...
- JedisCluster
字符串 setex(key, seconds, value):带过期时间 mset(keysvalues.....):批量操作,是一个原子性(atomic)操作,所有给定key会在同一时间内被设置 h ...
- mybatis-plus调用自身的 selectById 方法报错:org.apache.ibatis.binding.BindingException:
mybatis-plus的版本号是 2.0.1,在调用自身的insert(T)的时候没有报错,但是执行update报错,调用selectById.deleteById的时候也报错.也就是涉及到需要主键 ...
- 一个是EF内联多表查询,一个是EF中写SQL文。
public IList<MenuModel> GetAllMenu() { using (IMMEntities context = new IMMEntities()) { var m ...
- This is a DynamicProxy2 error:
- xadmin插件开发
参考:http://blog.csdn.net/qq_15682489/article/details/70174784 项目中新添加的organization模块需要在toolbar中添加“课表详细 ...
- Scrapy快速上手
超详细官方教程解析 https://blog.csdn.net/fly_yr/article/details/51540269 实战过程: 创建一个Scrapy项目 定义提取的Item 编写爬取网站的 ...
- Excel自动建组
已用于测试用例自动创建组 使用要求:A列的格式如:X.X.X.X.X11.11.1.11.1.1.11.1.1.1.11.1.1.21.1.21.22 会自动将1.1.1.1.1-1.1.1.1.X组 ...
- requests库入门02-简单了解HTTP协议
HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议. HTT ...