$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 <= ...
随机推荐
- 使用Postman Interceptor发送带cookie的请求一直loading的解决法案
很多web网页开发人员都知道Postman限制由于chrome安全的限制,发不出带cookie和带有自定义头部标签的请求.想要发出由于chrome安全的限制,发不出带cookie和带有自定义头部标签的 ...
- LINUX应用开发工程师职位(含答案)
就业模拟测试题-LINUX应用开发工程师职位 本试卷从考试酷examcoo网站导出,文件格式为mht,请用WORD/WPS打开,并另存为doc/docx格式后再使用 试卷编号:143989试卷录入者: ...
- STM32F103移值FreeRtos笔记
RTOS版本:FreeRTOS_V8.2.2 一.下载FreeRTOS源文件 这个可以在百度上下载,或者在官网上面下载http://www.freertos.org/a00104.html ...
- [luoguP3047] [USACO12FEB]附近的牛Nearby Cows(DP)
传送门 dp[i][j][0] 表示点 i 在以 i 为根的子树中范围为 j 的解 dp[i][j][1] 表示点 i 在除去 以 i 为根的子树中范围为 j 的解 状态转移就很好写了 ——代码 #i ...
- [luoguP3252] [JLOI2012]树(DP)
传送门 树上前缀和. 在树上找一条权值和为 s 的链,其中这个链上的点按深度递增(递减)(不同) dfs 每搜到一个点求它的前缀和 sum[x],放入 set 中. 在 set 中找 sum[x] - ...
- MYSQL常用的性能指标
(1) QPS(每秒Query量) QPS = Questions(or Queries) / seconds mysql > show global status like 'Questio ...
- RMAN RECOVERY
Data Recovery Advisor The health monitor and the ADR The capabilities and limitations of DRA using t ...
- 如何在eclipse中用maven编译
在eclipse中用maven编译的方法: 在项目中的“pom.xml”文件上点击右键,在弹出的菜单中选择“Run AS”à“Maveninstall”来编译和生成项目.如下图所示: 在编译和生成过程 ...
- nginx: 添加文件下载目录
修改nginx.conf,添加如下行: location /file/ { alias /usr/share/nginx/html/file/; add_header Content-di ...
- hdu 3555 Bomb 【数位DP】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题意:上一题是不要62 这个是"不要49" 代码: #include < ...