当前位置: 首页 > news >正文

AcWing 1097 池塘计数 flood fill bfs搜索

代码

#include <bits/stdc++.h>
using namespace std;const int N = 1010, M = N * N;typedef pair<int, int> PII;int n, m;char g[N][N];
bool st[N][N];
PII q[M];void bfs (int xx, int yy)
{int hh = 0, tt = -1;q[ ++ tt] = {xx, yy};st[xx][yy] = true;while (hh <= tt){int tx = q[hh].first, ty = q[hh].second;hh ++;for (int i = max(0, tx - 1); i <= min(n - 1, tx + 1); i ++ )for (int j = max(0, ty - 1); j <= min(m - 1, ty + 1); j ++ ){if (!st[i][j] && g[i][j] == 'W'){st[i][j] = true;q[ ++ tt] = {i, j};}}}
}int main()
{scanf("%d%d", &n, &m);for (int i = 0; i < n; i ++ ){scanf("%s", g[i]);}int ans = 0;for (int i = 0; i < n; i ++ )for (int j = 0; j < m; j ++ )if (g[i][j] == 'W' && !st[i][j]){
//				cout << i << " " << j << endl;bfs(i, j);ans ++;}printf("%d", ans);return 0;
}

http://www.lryc.cn/news/484294.html

相关文章:

  • R门 - rust第一课陈天 -内存知识学习笔记
  • java itext后端生成pdf导出
  • 信号-3-信号处理
  • 38配置管理工具(如Ansible、Puppet、Chef)
  • 网络技术-定义配置ACL规则的语法和命令
  • 动态规划一>子数组系列
  • 一觉睡醒,全世界计算机水平下降100倍,而我却精通C语言——scanf函数
  • Altium Designer使用技巧(五)
  • Docker 的安装与使用
  • Android Studio 中三方库依赖无法找到的解决方案
  • PGMP练-DAY24
  • 【C++动态规划 最长公共子序列】1035. 不相交的线|1805
  • FFmpeg的基本结构
  • react 受控组件和非受控组件
  • C语言模块化概述
  • WPF 中的视觉层和逻辑层有什么区别?
  • Kafka简单实践
  • JS
  • 【原创】java+ssm+mysql商品库存管理系统(进销存)设计与实现
  • three.js 杂记
  • 基于Hadoop、hive的数仓搭建实践
  • 新的恶意软件活动通过游戏应用程序瞄准 Windows 用户
  • 【Hutool系列】反射工具-ReflectUtil
  • 【操作系统专业课】第二次作业
  • Scala的迭代器
  • (RK3566驱动开发 - 1).pinctrl和gpio子系统
  • css三角制作(二十课)
  • C++_priority_queue(优先级队列)
  • 微信小程序——01开发前的准备和开发工具
  • MySQL 的主从复制数据同步