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 ...
随机推荐
- mybatis源码探索笔记-4(缓存原理)
前言 mybatis的缓存大家都知道分为一级和二级缓存,一级缓存系统默认使用,二级缓存默认开启,但具体用的时候需要我们自己手动配置.我们依旧还是先看一个demo.这儿只贴出关键代码 public in ...
- 【SSM 项目】实战总结
项目源代码
- PhpStorm For Mac 安装使用及 Php 开发的 ‘Hello World’
PHP全称为:Hypertext Preprocessor,中文名为:『超文本预处理 器』是一种通用开源脚本语言,主要用于Web应用开发(俗称做网站或 者做后台!) 编译软件:PHPStorm for ...
- [原]Java工程打包注意事项
注意事项(持续增加...): 如果Java工程中用到了注解,在用eclipse打jar包时需要注意一下,勾上“Add directory entries”,否则注解的类会注册不上
- 定时任务--mysql数据库备份
vim /home/back.sh #!/bin/bash USER="******" PASSWORD="******" DATABASE="*** ...
- tcp连接建立和断开
TCP协议作为传输层主要协议之一,具有面向连接,端到端,可靠的全双工通信,面向字节流的数据传输协议. 1.TCP报文段 虽然TCP面试字节流,但TCP传输的数据单元却是报文段.TCP报文段分为TCP首 ...
- MySQL : INSERT INTO SELECT
INSERT INTO wx_announcement_push ( title, content, STATUS, del_flag, user_login_name ) SELECT '大家好', ...
- Locale
1. Locale 概述 2. Windows 区域设置 3 Linux Locale 3.1 Linux Locale 语言环境名称格式 3.2 常用区域描述(简写)日期习惯 3.3 日期显示格式 ...
- java中如何修改事务的隔离级别
事务的特性: 原子性(Atomicity)原子性是指事务是一个不可分割的工作单位,事务中的操作要么都发生,要么都不发生. (多条语句要么都成功,要么都失败.) 一致性(Consistency)事务前后 ...
- ImagePullBackOff 错误处理
kubectl create -f nginx-deployment.yaml 执行之后,kubectl get pods 一致出现 ImagePullBackOff,一直无法执行成功. yaml文件 ...