$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 <= ...
随机推荐
- type、object、class之间的关系
class Foo: pass print(type(int)) # <class 'type'> print(type(str)) # <class 'type'> prin ...
- Xshell(smarTTY)连接Linux虚拟机失败(未开放22端口)解决办法
1.关闭防火墙: 命令:sudo ufw disable 2.安装openssh-server以及openssh-client: 命令:sudo apt-get install openssh-ser ...
- LINUX-系统信息
系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...
- list数组排序---stream
import java.util.*;import java.util.stream.Collector;import java.util.stream.Collectors; public clas ...
- at24c02系列和at24c256系列的比较
编号的含义: at24c02系列包括的有: 128(1K),256(2K),512(4K),1024(8K),2048(16K)字节(B) at24c256系列包括的有: 16384(128K),32 ...
- Apache Maven Cookbook(一)maven 使用命令创建、编译java项目
一.创建 使用命令创建项目分几步: 1.打开命令行窗口,比如cmd,把目录切换至想要创建项目地方. 2.执行如下命令: mvn archetype:generate -DgroupId=com.zua ...
- Leetcode 115.不同的子序列
不同的子序列 给定一个字符串 S 和一个字符串 T,计算在 S 的子序列中 T 出现的个数. 一个字符串的一个子序列是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串.(例 ...
- Uva10562
Professor Homer has been reported missing. We suspect that his recent research works might have had ...
- 在IIS6,7中部署ASP.NET网站[转]
阅读目录 开始 查看web.config文件 在IIS中创建网站 IIS6 添加扩展名映射 IIS6 无扩展名的映射 目录的写入权限 SQL SERVER的配置 在IIS7中部署ASP.NET程序 8 ...
- PHP小白学习日程之旅
我是一名专升本的学生,在这里偶然接触了博客园,我觉得非常好,每天可以在这里看别人的分享与学习,还会在大学学习俩年,我只想专注的吧自己的技术提高,跟园子里的朋友们一起学习与分享加油!!!!!!!!!!! ...