【POJ - 2386】Lake Counting (dfs+染色)
-->Lake Counting
直接上中文了
Descriptions:
给你约翰农场的航拍图,确定有多少池塘
Input
Line 1: N 和 M
Output
Line 1: 池塘的数量
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
左下方,左上方,右边三块
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 1000
using namespace std;
int n,m;
int num;//总共几种颜色
int vis[Maxn][Maxn];//染色计数
char mp[Maxn][Maxn];//原始地图
int dt[][]= {{,},{-,},{,},{,-},{,},{,-},{-,-},{-,}};//八个方向
bool judge(int xx,int yy)//判断是否满足条件
{
if(!vis[xx][yy]&&mp[xx][yy]=='W')//没有被染色且这个地方是"W"
return true;
return false;
}
void dfs(int x,int y)
{
if(vis[x][y])
return;
vis[x][y]=num;
for(int i=;i<;i++)//八个方向
{
int tx=x+dt[i][];
int ty=y+dt[i][];
if(judge(tx,ty))
dfs(tx,ty);
}
}
int main()
{
num=;
MEM(vis,);
cin>>n>>m;
for(int i=;i<n;i++)//读入地图
for(int j=;j<m;j++)
cin>>mp[i][j];
for(int i=;i<n;i++)//开始搜索
for(int j=;j<m;j++)
{
if(judge(i,j))
{
num++;
dfs(i,j);
}
}
cout<<num<<endl;
}
【POJ - 2386】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 ...
- POJ 2386 Lake Counting DFS水水
http://poj.org/problem?id=2386 题目大意: 有一个大小为N*M的园子,雨后积起了水.八连通的积水被认为是连接在一起的.请求出院子里共有多少水洼? 思路: 水题~直接DFS ...
- 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(深搜)
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 ...
- POJ 2386 Lake Counting(搜索联通块)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48370 Accepted: 23775 Descr ...
- POJ 2386 Lake Counting 八方向棋盘搜索
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 53301 Accepted: 26062 D ...
- poj - 2386 Lake Counting && hdoj -1241Oil Deposits (简单dfs)
http://poj.org/problem?id=2386 http://acm.hdu.edu.cn/showproblem.php?pid=1241 求有多少个连通子图.复杂度都是O(n*m). ...
- POJ 2386——Lake Counting(DFS)
链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace st ...
随机推荐
- bigdata_mac下安装spark_scala
Java 下载安装Mac对应版本的JDK. Apache-spark $ brew update $ brew info apache-spark $ brew install apache-spar ...
- 使用HANDLE_MSG宏简化Win32应用的开发
http://blog.csdn.net/daiyutage/article/details/17241161 Win32应用中的回调函数WndProc用于接收Windows向应用程序直接发送的消息, ...
- XF 定制图片
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 【msdn wpf forum翻译】TextBox中文本 中对齐 的方法
原文:[msdn wpf forum翻译]TextBox中文本 中对齐 的方法 原文链接:http://social.msdn.microsoft.com/Forums/en-US/wpf/threa ...
- Socket 专题
Socket小白篇-附加TCP/UDP简介 Socket 网络通信的要素 TCP和UDP Socket的通信流程图 1.Socket 什么是Socket Socket:又称作是套接字,网络上的两个程序 ...
- 破处在window7桌面版本下golang连接数上限
注册表 HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters 修改或者添加 MaxUserPort 60000 TcpTimedWaitDel ...
- SQLServer 复制中移除和添加发布而不初始化所有项目
原文:SQLServer 复制中移除和添加发布而不初始化所有项目 -- 若提前"禁止架构更改",新增的列不会自动添加大发布,此时应使用 sp_articlecolumn 添加列 E ...
- 子函数内malloc分配内存,论如何改变指针参数所指内存,二级指针、三级指针的应用
工作中优化一段代码,代码中有一大段分配堆内存的内容,我觉得这段代码太长了,更适合放在子函数里面. 我把指针作为参数,然后在子函数中malloc分配内存,结果出现了问题,函数结束后,以参数传进来的指针并 ...
- 如何把zip文件直接解压到内存里?
解压到硬盘再读进来耽误时间. var LZip: TZipFile; LMem: TMemoryStream; LBytes: TBytes;begin LZip := TZipFile.Cr ...
- 高效的DDoS攻击探测与分析工具 – FastNetMon
快速使用Romanysoft LAB的技术实现 HTML 开发Mac OS App,并销售到苹果应用商店中. <HTML开发Mac OS App 视频教程> 土豆网同步更新:http: ...