\(problem\)

其实这题吧\(DFS\)好写一点(大雾

所以就不讲\(DFS\)了 em

\(BFS\)的话 主要是 判重。 方向。 队列。(没了吧

至于位置 用两个队列?还是\(pair\)?还是结构体?

\[\text{结构体大法好啊。emm}
\]

#ifdef Dubug

#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() { LL res(0),f(1); register char c ;
while(isspace(c=getchar())) ; c == '-'? f = -1 , c = getchar() : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ;
return res * f ;
}
int n , m ;
const int N = 100 + 5 ;//范围
char c[N][N] ;
bool vis[N][N] ;
struct node {
int x , y ;
};
queue < node > q ;
int dx[] = {0,0,0,1,-1,1,1,-1,-1} ;
int dy[] = {0,1,-1,0,0,-1,1,-1,1} ;//8个方向。
int ans = 0 ;
inline void bfs(int i,int j) {//累加ans的值 因为一个水坑只会判断一次。
ans ++ , q.push(node{i,j}) , vis[i][j] = true ;//第一个特殊处理。
while(!q.empty()) {
int x = q.front().x , y = q.front().y ; q.pop() ;//取出来一个。
for(register int i=1;i<=8;i++){//不习惯 下标从 0 开始
int cx = x + dx[i] , cy = y + dy[i] ;
if(vis[cx][cy] or cx > n or cx < 1 or cy > m or cy < 1 or c[cx][cy] != 'W') continue ;//不符合条件就跳过。
q.push(node{cx,cy}) , vis[cx][cy] = true ;//入队。
}
}
}
signed main() {
memset(vis,0,sizeof(vis)) ;
n = In() , m = In() ;
for(register int i=1;i<=n;i++)
for(register int j=1;j<=m;j++) cin >> c[i][j] ;
for(register int i=1;i<=n;i++)
for(register int j=1;j<=m;j++) if(!vis[i][j] and c[i][j] =='W') bfs(i,j) ;//bfs
cout << ans << endl ;//输出答案
return 0 ;
}

$P1596 [USACO10OCT]湖计数Lake Counting$的更多相关文章

  1. 洛谷 P1596 [USACO10OCT]湖计数Lake Counting

    题目链接 https://www.luogu.org/problemnew/show/P1596 题目描述 Due to recent rains, water has pooled in vario ...

  2. 洛谷——P1596 [USACO10OCT]湖计数Lake Counting

    P1596 [USACO10OCT]湖计数Lake Counting 题目描述 Due to recent rains, water has pooled in various places in F ...

  3. 洛谷P1596 [USACO10OCT]湖计数Lake Counting

    https://www.luogu.org/problemnew/show/P1596 连通块水题... 大体思路是找到是水坑的坐标然后就开始不断递归,往八个方向搜,把连在一起的都标记一遍直到找不到为 ...

  4. Luogu P1596 [USACO10OCT]湖计数Lake Counting

    题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is repres ...

  5. P1596 【[USACO10OCT]湖计数Lake Counting】

    可爱的题面君~~ 个人感觉这题还是很简单的,就是一个完全不加工的找联通块个数 个人解题思路是先读入,然后循环一遍,遇到水就dfs,并把这个w所在的联通块“删除”,并在答案上加一 最后输出答案 具体注释 ...

  6. [USACO10OCT]湖计数Lake Counting 联通块

    题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is repres ...

  7. Poj2386 Lake Counting (DFS)

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49414   Accepted: 24273 D ...

  8. POJ 之2386 Lake Counting

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20003   Accepted: 10063 D ...

  9. 【POJ - 2386】Lake Counting (dfs+染色)

    -->Lake Counting 直接上中文了 Descriptions: 由于近日阴雨连天,约翰的农场中中积水汇聚成一个个不同的池塘,农场可以用 N x M (1 <= N <= ...

随机推荐

  1. Python面向对象,析构继承多态

    析构: def __del__(self): print("del..run...") r1 = Role("xx") del r1 结果打印del..run. ...

  2. 【Python实践-9】将字符串转化为浮点型

    利用map和reduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456. 思路:计算小数位数--->将字符串中的小数点去掉--->字符串转换为整数-- ...

  3. Java核心技术 卷一 复习笔记(乙

    1.字符串从概念上讲,Java字符串就是Unicode字符序列.Java没有内置的字符串类型,而是在标准Java类库中提供了一个预定义类,叫String. 每个用双引号括起来的字符串都是 String ...

  4. 56-混沌操作法之我见:二、AO、AC指标.(2015.2.9)

    混沌操作法之我见:二.AO.AC指标 先看看其算法: Y=(H+L)/2: AO=MA(Y,5)-MA(Y,34): AC=AO-MA(AO,5). 由算法可以看出,AO表示的是近5期的综合价格与近3 ...

  5. BZOJ 3747 洛谷 3582 [POI2015]Kinoman

    [题解] 扫描线+线段树. 我们记第i部电影上次出现的位置是$pre[i]$,我们从$1$到$n$扫描,每次区间$(pre[i],i]$加上第i部电影的贡献$w[f[i]]$,区间$[pre[pre[ ...

  6. PAT 1135 Is It A Red-Black Tree

    There is a kind of balanced binary search tree named red-black tree in the data structure. It has th ...

  7. Git学习总结(14)——Git使用前的注意事项

    连接方式https.ssh 在使用git的时候,不管你的服务器是开源平台github还是私服gitlab,你都需要clone仓库到本地,这个clone的时候就需要你选择连接方式.这个连接方式决定了你与 ...

  8. java 日历计算农历和节假日的工具类

    背景 业务需求需要后端提供这样的接口,网上找了很多java代码例子,虽然功能实现了 但是不完善,特别是节日那一块儿.然后百度发现有这样的插件,但是信息也是java后端提供的非js 然后在开源js插件找 ...

  9. 智能家居APP开发

    智能家居APP开发 APP开发技术qq交流群:347072638 前言,随着智能硬件设备的流行,智能家居開始红火,智能家居就是家用电器的智能化.包含智能锁,灯,空调,灯,音箱等等,移动设备通过WIFI ...

  10. HDOJ题目4417 Super Mario(划分树求区间比k小的个数+二分)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...