【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 ...
随机推荐
- WPF编游戏系列 之四 用户控件
原文:WPF编游戏系列 之四 用户控件 在上一篇<WPF编游戏系列 之三 物品清单>中,对物品清单进行了演示,其中反复用到了同一组控件(如下图),而且 颜昌钢也指出在3.2. ...
- mysql 优化 读写分离 主从复制
1:mysql所在服务器内核 优化 ---------此优化可由系统运维人员完成 2:mysql配置参数优化(my.cnf) -------- 此优化需进行压力测试来进行参数调整 3:sql语句及表 ...
- ASP FirstWeb
//html <!DOCTYPE html> <html><head><meta http-equiv="Content-Type" co ...
- 重启网卡的几种方法(命令行,API,
1.重启windows网卡命令 rem 禁用网卡netsh interface set interface 本地连接 disabledrem 启用网卡 netsh interface set inte ...
- Visual Studio更改编码格式为“UTF-8”
原文:Visual Studio更改编码格式为"UTF-8" 用VS2015新建了个Python文件,在VS2015打开时中文显示正常, 用Visual Studio Code文本 ...
- Struts2之Struts2
Struts2-2.5.5版本是目前为止最新的版本了,相对于之前的2.3版本以及再之前的版本而言,新版本改动了很多. 好了,废话不多说,GO CODE! 基本jar包: web.xml核心配置,这里要 ...
- sqlserver检查sql执行时间
set statistics profile onset statistics io onset statistics time onGO select * from mytable; goset s ...
- Linux下C语言RPC(远程过程调用)编程实例
在查看libc6-dev软件包提供的工具(用 dpkg -L libc6-dev 命令)的时候,发现此软件包提供了一个有用的工具rpcgen命令.通过rpcgen的man手册看到此工具的作用是把RPC ...
- 腾讯QQ 8.9.3体验版发布 在线文档多端同步实时保存
感谢N软网的投递 腾讯体验中心迎来QQ8.9.3首个维护体验版发布,详细版本号为v8.9.3.21006,上一个体验版v8.9.2.20717发布于4月20日,时隔34天又迎来了更新.本次升级主要是在 ...
- Oracle报错:不是GROUP BY 表达式
报错:不是GROUP BY 表达式 实例:select sum(hwjz),rq from JcChargeInfo where 1=1 group by rq order by jcchargec ...