Ai
1 Star 0 Fork 0

util6/算法刷题c++

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Acwing1097_LakeCounting.cpp 1018 Bytes
一键复制 编辑 原始数据 按行查看 历史
util6 提交于 2022-01-29 18:23 +08:00 . 默认的
/**
* https://www.luogu.com.cn/problem/P1596
*/
#include "iostream"
#include "queue"
using namespace std;
const int N = 1010;
int n, m;
char g[N][N];
bool range[N][N];
void bfs(int sx, int sy) {
queue<pair<int, int>> q;
q.push({sx, sy});
while (q.size()) {
auto t = q.front();
q.pop();
for (int i = t.first - 1; i <= t.first + 1; i++) {
for (int j = t.second - 1; j <= t.second + 1; j++) {
if (i == t.first && j == t.second)continue;
if (i >= n || i < 0 || j >= m || j < 0 || range[i][j] || g[i][j] == '.')continue;
q.push({i, j});
range[i][j] = true;
}
}
}
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++)cin >> g[i];
int res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!range[i][j] && g[i][j] == 'W') {
bfs(i, j);
res++;
}
}
}
cout << res;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuyutaocode/cppCode.git
git@gitee.com:liuyutaocode/cppCode.git
liuyutaocode
cppCode
算法刷题c++
master

搜索帮助