Lake Counting(DFS连通图)
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<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
char map[][];
int vis[][];///标记数组
int dir[][]={{,},{-,},{,},{,-},{,},{-,-},{,-},{-,}};
int n,m;
void DFS(int x,int y)
{
int a,b,i;
vis[x][y]=;
for(i=;i<;i++)
{
a=x+dir[i][];
b=y+dir[i][];
if(a>=&&a<n&&b>=&&b<m&&vis[a][b]==&&map[a][b]=='W')
{
DFS(a,b);
}
}
return ;
}
int main()
{
int count,i,j;
memset(map,,sizeof(map));
memset(vis,,sizeof(vis));
scanf("%d%d",&n,&m);
getchar();
count=;
for(i=;i<n;i++)
{
scanf("%s",map[i]);
}
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
if(vis[i][j]==&&map[i][j]=='W')
{
count++;
DFS(i,j);
}
}
}
printf("%d\n",count);
return ;
}
Lake Counting(DFS连通图)的更多相关文章
- [POJ 2386] Lake Counting(DFS)
Lake Counting Description Due to recent rains, water has pooled in various places in Farmer John's f ...
- Lake Counting (DFS)
N*M的园子,雨后积起了水.八连通的积水背认为是连接在一起的.请求出园子里总共有多少水洼? dfs(Depth-First Search) 八个方向的简单搜索.... 深度优先搜索从最开始的状态出 ...
- POJ 2386 Lake Counting DFS水水
http://poj.org/problem?id=2386 题目大意: 有一个大小为N*M的园子,雨后积起了水.八连通的积水被认为是连接在一起的.请求出院子里共有多少水洼? 思路: 水题~直接DFS ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
- 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 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 ...
- Openjudge1388 Lake Counting【DFS/Flood Fill】
http://blog.csdn.net/c20182030/article/details/52327948 1388:Lake Counting 总时间限制: 1000ms 内存限制: ...
- POJ2386 Lake Counting 【DFS】
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20782 Accepted: 10473 D ...
随机推荐
- HTML | video的封面平铺方法
<video style="object-fit:fill;"></video>
- 邮箱,ip,叠词的正则处理方式
package com.regexTest; import java.util.TreeSet; public class RegexTest { public static void main(St ...
- C#获取本地磁盘信息
直接上干货简单易懂 //磁盘监控(远程/本地) //需要引用System.Management.dll public class RemoteMonitoring { private static s ...
- windows下nginx的安装
一. 下载 http://nginx.org/ (下载后解压) 二. 修改配置文件 nginx配置文件在 nginx-1.8.0\conf\nginx.conf http { gzip on; ...
- STM32F407+STemwin学习笔记之STemwin移植
原文链接:http://www.cnblogs.com/NickQ/p/8748011.html 环境:keil5.20 STM32F407ZGT6 LCD(320*240) STemwin:S ...
- 用matplotlib库画图
1.用例一 import matplotlib.pyplot as plt import numpy as np x=np.linspace(0,10,100) y=np.cos(2*np.pi*x) ...
- 常用 Maven 配置
打包为带依赖的 JAR <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEnc ...
- 破解使用SMB协议的Windows用户密码:acccheck
一.工作原理 Acccheck是一款针对微软的SMB协议的探测工具(字典破解用户名和密码),本身不具有漏洞利用的能力. SMB协议:SMB(Server Message Block)通信协议主要是作为 ...
- Java线程和多线程(十一)——BlockingQueue
这次讨论的是Java的BlockingQueue,java.util.concurrent.BlockingQueue是一个Java的队列接口,支持一系列操作,比如,在获取和移除对象的时候如果队列为空 ...
- 洛谷P4136 谁能赢呢?
题目描述 小明和小红经常玩一个博弈游戏.给定一个n×n的棋盘,一个石头被放在棋盘的左上角.他们轮流移动石头.每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的格子之前不能被访问 ...