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 ...
随机推荐
- vue 里面引入高德地图
效果图: 实现: 一:引入 高德,web-sdk (两种方式) 1:在html 中引入(我用的这一种) <script type="text/javascript" src= ...
- HTML标签使用
`<!-- 什么是HTML 超文本标记语言 由标签(属性和实体组成)和内容组成 --> <!-- 定义文档类型 --> <!DOCTYPE html> <!- ...
- 在shell终端操作oracle数据库的常用命令
这里面是在一个项目中用到的操作oracle数据库的常用linux命令,因为当时无法用plsql远程连接,大部分操作都需要在命令行窗口进行,总结一下 第一种方式 (1)先切换至sqlplus [orac ...
- 安卓四大组件之Sevice组件的简单使用 --Android基础
1.本例实现了简单的Service(服务)的创建.启动和停止,点击“启动SERVICE”页面会显示“服务被创建”,接着是“服务被启动”.点击“停止SERVICE”页面提示“服务被停止”.太过基础,直接 ...
- WCF开发框架形成之旅---WCF的几种寄宿方式
WCF开发框架形成之旅---WCF的几种寄宿方式 WCF寄宿方式是一种非常灵活的操作,可以在IIS服务.Windows服务.Winform程序.控制台程序中进行寄宿,从而实现WCF服务的运行,为调用者 ...
- 从早期 Spring Boot 版本升级
如果你现在正在从早期的 Spring Boot 版本进行升级的话,请访问 “migration guide” on the project wiki 页面,这个页面提供了有关升级的详细指南.同时也请查 ...
- slf4j日志用法
在pom.xml中添加日志依赖 <!--slf4j--> <dependency> <groupId>org.slf4j</groupId> <a ...
- 廖雪峰网站:学习python函数—调用函数(一)
# 调用函数 # 可以直接从Python的官方网站查看文档: # http://docs.python.org/3/library/functions.html#abs n = abs(100) # ...
- Android(二)——frida安装教程
pc端下载:pip install frida 之后就是在手机端或者模拟器下载对应版本的server 在手机或者模拟器上查看cpu版本型号,就根据这个来下载server system/build.pr ...
- meta标签常用设置
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang="zh-cmn-Hans"&g ...