DFS----Lake Counting (poj 2386)
Lake Counting(POJ No.2386)
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
1 #include <iostream>
2 using namespace std;
3 int N,M;
4 //int res=0;
5 const int MAX_N=1000;
6 const int MAX_M=1000;
7 char field[MAX_N][MAX_M];
8 void dfs(int x,int y)
9 {
10 field[x][y]='.';
11 for(int dx=-1;dx<=1;dx++)
12 {
13 for(int dy=-1;dy<=1;dy++)
14 {
15 int nx=dx+x,ny=dy+y;
16 if(nx>=0&&nx<N&&ny>=0&&ny<M&&field[nx][ny]=='W')
17 dfs(nx,ny);
18 }
19 }
20 return;
21 }
22 void solve()
23 {
24 int res=0;
25 for(int i=0;i<N;i++) {
26 for(int j=0;j<M;j++){
27 if(field[i][j]=='W') {
28 dfs(i, j);
29 res++;
30 }
31 }
32 }
33 cout<<res<<endl;
34 }
35 int main() {
36 cin>>N>>M;
37 for(int x=0;x<N;x++)
38 {
39 for(int y=0;y<M;y++)
40 {
41 cin>>field[x][y];
42 }
43 // printf("\n");
44 }
45 solve();
46 //cout<<res<<endl;
47 return 0;
48 }
DFS----Lake Counting (poj 2386)的更多相关文章
- Lake Counting(poj 2386)
题目描述: Description Due to recent rains, water has pooled in various places in Farmer John's field, wh ...
- DFS:Lake Counting(POJ 2386)
好吧前几天一直没更新博客,主要是更新博客的确是要耗费一点精力 北大教你数水坑 最近更新博客可能就是一点旧的东西和一些水题,主要是最近对汇编感兴趣了嘻嘻嘻 这一题挺简单的,没什么难度,简单深搜 #inc ...
- Lake Counting (POJ No.2386)
有一个大小为N*M的园子,雨后积起了水,八连通的积水被认为是链接在一起的求出园子里一共有多少水洼? *** *W* *** /** *进行深度优先搜索,从第一个W开始,将八个方向可以到达的 W修改为 ...
- [POJ 2386] Lake Counting(DFS)
Lake Counting Description Due to recent rains, water has pooled in various places in Farmer John's f ...
- 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: 17917 Accepted: 906 ...
- POJ 2386 Lake Counting
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28966 Accepted: 14505 D ...
随机推荐
- app和bootloader跳转 MSP与PSP
1.不要把跳转函数放在中断中,如此导致在跳转后的app或者bootloder都是在中断状态,只要你一开启该中断,就可能出现硬件中断了 2.如果你的APP使用了ucos系统,在跳转函数中还需要增加__s ...
- (转)c# 属性与索引器
属性是一种成员,它提供灵活的机制来读取.写入或计算私有字段的值. 属性可用作公共数据成员,但它们实际上是称为“访问器”的特殊方法. 这使得可以轻松访问数据,还有助于提高方法的安全性和灵活性. 一个简单 ...
- python3 语法小结
(1) 关键字 # -*- coding: utf-8 -*- #!/usr/bin/python3 """ 1.关键字(保留字) ['False', 'None', ' ...
- thinkphp5.0写的项目放到服务器上 lnmp 404
tp5在Nginx上不适用pathinfo格式的url,在项目的Nginx配置文件里找到include enable-php.conf 改为 include enable-php-pathinfo.c ...
- 网络基础之 tcp/ip五层协议 socket
1 网络通信协议(互联网协议) 1.1 互联网的本质就是一系列的网络协议 1.2 osi七层协议 1.3 tcp/ip五层模型讲解 1.3.1 物理层 1.3.2 数据链路层 1.3.3 网络层 1. ...
- 『MXNet』第四弹_Gluon自定义层
一.不含参数层 通过继承Block自定义了一个将输入减掉均值的层:CenteredLayer类,并将层的计算放在forward函数里, from mxnet import nd, gluon from ...
- Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined)G. Sum the Fibonacci
题意:给一个数组s,求\(f(s_a | s_b) * f(s_c) * f(s_d \oplus s_e)\),f是斐波那契数列,而且要满足\(s_a\&s_b==0\),\((s_a | ...
- vue嵌套路由--params传递参数
在嵌套路由中,父路由向子路由传值除了query外,还有params,params传值有两种情况,一种是值在url中显示,另一种是值不显示在url中. 1.显示在url中index.html <d ...
- PAT 1027 Colors in Mars
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way ...
- NPM 使用及npm升级中问题解决
NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种: 允许用户从NPM服务器下载别人编写的第三方包到本地使用. 允许用户从NPM服务器下载并 ...