$P1596 [USACO10OCT]湖计数Lake Counting$
其实这题吧\(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$的更多相关文章
- 洛谷 P1596 [USACO10OCT]湖计数Lake Counting
题目链接 https://www.luogu.org/problemnew/show/P1596 题目描述 Due to recent rains, water has pooled in vario ...
- 洛谷——P1596 [USACO10OCT]湖计数Lake Counting
P1596 [USACO10OCT]湖计数Lake Counting 题目描述 Due to recent rains, water has pooled in various places in F ...
- 洛谷P1596 [USACO10OCT]湖计数Lake Counting
https://www.luogu.org/problemnew/show/P1596 连通块水题... 大体思路是找到是水坑的坐标然后就开始不断递归,往八个方向搜,把连在一起的都标记一遍直到找不到为 ...
- Luogu P1596 [USACO10OCT]湖计数Lake Counting
题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is repres ...
- P1596 【[USACO10OCT]湖计数Lake Counting】
可爱的题面君~~ 个人感觉这题还是很简单的,就是一个完全不加工的找联通块个数 个人解题思路是先读入,然后循环一遍,遇到水就dfs,并把这个w所在的联通块“删除”,并在答案上加一 最后输出答案 具体注释 ...
- [USACO10OCT]湖计数Lake Counting 联通块
题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is repres ...
- Poj2386 Lake Counting (DFS)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 49414 Accepted: 24273 D ...
- POJ 之2386 Lake Counting
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20003 Accepted: 10063 D ...
- 【POJ - 2386】Lake Counting (dfs+染色)
-->Lake Counting 直接上中文了 Descriptions: 由于近日阴雨连天,约翰的农场中中积水汇聚成一个个不同的池塘,农场可以用 N x M (1 <= N <= ...
随机推荐
- L2-012. 关于堆的判断(STL中heap)
L2-012. 关于堆的判断 将一系列给定数字顺序插入一个初始为空的小顶堆H[].随后判断一系列相关命题是否为真.命题分下列几种: “x is the root”:x是根结点: “x and y ...
- docker CE 的安装
一.Docker CE的安装1.先决条件运行环境:Ubuntu 64位或者其他支持Docker的64位系统运行配置,linux内核版本必须大于 3.10,否则会因为缺少容器运行所需的功能而出错. 2. ...
- npm安装node包时怎么显示安装进度
npm config set loglevel=http 打开这个你会看到所有的 HTTP 请求,除此之外如果还有 \ 长时间打转,那就是外部模块的编译过程,一个字:等. 具体地址可参考https:/ ...
- 【Codeforces 924C】Riverside Curio
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设第i天总共的线数为t[i] 水平线上线数为m[i]是固定的 水平线下的线数设为d[i] 则d[i]+m[i]+1=t[i] 也就是说问题可以 ...
- 泛型转换https://www.cnblogs.com/eason-chan/p/3633210.html
import java.lang.reflect.ParameterizedType;import java.lang.reflect.Type;//总结1.st.getClass==Student. ...
- mysql MVCC原理理解
MVCC多版本控制: 指的是一种提高并发的技术.最早的数据库系统,只有读读之间可以并发,读写,写读,写写都要阻塞.引入多版本之后,只有写写之间相互阻塞,其他三种操作都可以并行,这样大幅度提高了Inno ...
- vue2源码浏览分析02
1.组件初始化方法 init Vue.prototype._init = function (options) { /* istanbul ignore if */ if ("develop ...
- JWPlayer Uncaught Error: Invalid SRT file
错误场景: JWPlayer 播放视频,加入了字幕和缩略图: 字幕为Srt格式: 1 00:00:00,000 --> 00:00:02,000 战略管理过程 2 00:00:03,000 -- ...
- j2se回想
执行Java程序. Java程序有两种方式一种是jar包.一种是class. 执行jar,Java -jar XXX.jar执行的时候,Java.exe调用GetMainClassName函数,该函数 ...
- 可编程数据平面将OpenFlow扩展至电信级应用(一)
可编程数据平面将OpenFlow扩展至电信级应用(一) 案例:基于WinPath网络处理器的电信极OpenFlow (CG-OF)client实现 作者:Liviu Pinchas, Tao Lang ...