【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从源对象提取一些信息,并用这些信息设置目标对象的属性.目标属性是依赖项属性.源对象可以是任何内容,从另一个WPF元素乃至ADO. ...
- nodejs timer block-timer timer-ease
https://www.npmjs.org/package/block-timer https://www.npmjs.org/package/timer-ease 来自为知笔记(Wiz)
- 启动组织重整 Marvell追求创新文化
最近接任Marvell技术长的Neil Kim正是该公司亟需的人才——他在今年四月加入后,预计将为Marvell带来正面.积极的改革契机,有机会让该公司彻底改头换面... 迈威尔科技(Marvell) ...
- 【转】微信退款时候报”请求被中止: 未能创建 SSL/TLS 安全通道“或”The request was aborted: Could not create SSL/TLS secure channel“的错误
退款测试在我本机测试一切都是正常的,但是发布到了服务器就报这样的一个错啦 但是无论百度或者google或者bing,你能够搜索到的结果都很类似,综合起来就是加这样一些代码,如下 ServicePoin ...
- C#根据对象的指定字段去除重复值
PersonInfo类: public class PersonInfo { public int Index; public string Name; public override string ...
- Android零基础入门第4节:正确安装和配置JDK, 高富帅养成第一招
原文:Android零基础入门第4节:正确安装和配置JDK, 高富帅养成第一招 在前几期中总结分享了Android的前世今生.Android 系统架构和应用组件那些事.带你一起来聊一聊Android开 ...
- fastjson 出现首字母小写的问题
今天工作使用fastjson要求传过去的参数全为大写,在使用的过程中发现它自动将我的字段首字母转为小写了,在网上查了一些资料,发现下面的这个挺好,比其他的要方便. package com.alibab ...
- Auto updater for my side loaded UWP apps
原文: Auto updater for my side loaded UWP apps As I described before, i have a few tasks to solve for ...
- MySQL操作详解
创建并使用数据库 查看服务器上的数据库:SHOW DATABASES; 创建数据库:CREATE DATABASE <数据库名>; 指明使用何数据库:USE <数据库名> 创建 ...
- delphi多版本安装方法
delphi tokyo和其他版本并存的安装方法 1.安装delphi 10.2 tokyo 破解后写入D:\Program Files (x86)\Embarcadero\Studio\19.0\b ...