POJ 2386 Lake Counting 八方向棋盘搜索
Lake Counting
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 53301 | Accepted: 26062 |
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.
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int dir[][]={{,-},{,},{,},{-,},{-,},{,},{-,-},{,-}};
char a[][];
int n,m;
int check(int x,int y)
{
if(x>=&&x<n&&y>=&&y<m&&a[x][y]=='W')
return ;
else
return ;
}
void dfs(int x,int y)
{
if(check(x,y)==)
return;
if(a[x][y]=='W')
a[x][y]='.';
for(int i=;i<;i++)
{
int dx,dy;
dx=x+dir[i][];
dy=y+dir[i][];
dfs(dx,dy);
}
}
int main()
{
cin>>n>>m;
int cnt=;
for(int i=;i<n;i++)
cin>>a[i];
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(a[i][j]=='W')
{
dfs(i,j);
cnt++;
}
}
}
cout<<cnt<<endl;
return ;
}
POJ 2386 Lake Counting 八方向棋盘搜索的更多相关文章
- POJ 2386 Lake Counting(搜索联通块)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48370 Accepted: 23775 Descr ...
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
- POJ 2386 Lake Counting(深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17917 Accepted: 906 ...
- POJ:2386 Lake Counting(dfs)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40370 Accepted: 20015 D ...
- POJ 2386 Lake Counting
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28966 Accepted: 14505 D ...
- [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 搜索题解
简单的深度搜索就能够了,看见有人说什么使用并查集,那简直是大算法小用了. 由于能够深搜而不用回溯.故此效率就是O(N*M)了. 技巧就是添加一个标志P,每次搜索到池塘,即有W字母,那么就觉得搜索到一个 ...
- POJ 2386——Lake Counting(DFS)
链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace st ...
- POJ 2386 Lake Counting 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=2386 <挑战程序设计竞赛>习题 题目描述Description Due to recent rains, water has ...
随机推荐
- sshpass安装以及使用
centos7如何安装sshpass 先安装epel yum install -y epel-release yum repolist 安装完成epel之后,就可以按照sshpass了 yum ins ...
- Spring中@MapperScan注解
之前是,直接在Mapper类上面添加注解@Mapper,这种方式要求每一个mapper类都需要添加此注解,麻烦. 通过使用@MapperScan可以指定要扫描的Mapper类的包的路径,比如: @Sp ...
- Mysql基本用法-存储引擎-03
看到存储引擎这个地方感到很多细节比较陌生,所以总结小记一些 为了适应各种不同的运行环境,MYSQL提供了多种不同的存储引擎(Storage Engine ),在应用程序开发这个层面上,开发者可以根据不 ...
- 详解python的数字类型变量与其方法
以下内容引自:https://www.jb51.net/article/97752.htm python数据类型是不允许改变的,这就意味着如果改变 Number 数据类型的值,将重新分配内存空间.下面 ...
- 使用win32com操作woord的方法记录
CSDN博客平台中有众多的 win32com 库操作word 的说明,对于通用的内容将一笔带过,主要介绍目前看来独一无二的内容. import win32com from win32com.clien ...
- Java中短路
当使用逻辑运算符时,我们会遇到一种“短路”的现象.即一旦能够准确无误的确定整个表达式的值,就不再计算表达式余下的部分了.因此整个表达式靠后的部分有可能不被运算 /**短路 * @param args ...
- asp.net core配置下载文件
asp.net core的wwwroot文件夹下默认时保存静态文件的地方,外面可以直接访问,但是如果是一些无法识别的后缀文件,如(.apk),会报错404 如果想要实现下载这些文件,在配置静态文件中间 ...
- day11 作业
# 1.编写装饰器,为多个函数加上认证的功能(用户的账号密码来源于文件), # 要求登录成功一次,后续的函数都无需再输入用户名和密码 # FLAG = False # def login(func): ...
- springmvc面试问题
1.讲下SpringMvc和Struts1,Struts2的比较的优势 性能上Struts1>SpringMvc>Struts2 开发速度上SpringMvc和Struts2差不多,比St ...
- 设置npm源的几种方式
设置npm源的几种方式 原始源 # the original source https://registry.npmjs.org/ 方案: 使用nrm 安装 npm install -g nrm 列出 ...