From eeca85695a9adb54085b7e4eff7cb9fbf06c5b58 Mon Sep 17 00:00:00 2001 From: Leo <57850665+Jay-Chou118@users.noreply.github.com> Date: Sat, 19 Jul 2025 13:38:02 +0800 Subject: [PATCH] =?UTF-8?q?Update=200101.=E5=AD=A4=E5=B2=9B=E7=9A=84?= =?UTF-8?q?=E6=80=BB=E9=9D=A2=E7=A7=AF.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这道题目的意思应该是计算孤岛个数吧,根据题意, 对于 5 6 1 1 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 这个输入,应该输出是1. 但是按照卡哥的代码,输出会是2,问题就出在应该是找到==1的陆地后,继续进行dfs,而不是直接count++ 我这边是只修改dfs的部分,还没修改bfs 的部分 --- ...2\233\347\232\204\346\200\273\351\235\242\347\247\257.md" | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git "a/problems/kamacoder/0101.\345\255\244\345\262\233\347\232\204\346\200\273\351\235\242\347\247\257.md" "b/problems/kamacoder/0101.\345\255\244\345\262\233\347\232\204\346\200\273\351\235\242\347\247\257.md" index b3f66b96d8..6cb66d17dd 100644 --- "a/problems/kamacoder/0101.\345\255\244\345\262\233\347\232\204\346\200\273\351\235\242\347\247\257.md" +++ "b/problems/kamacoder/0101.\345\255\244\345\262\233\347\232\204\346\200\273\351\235\242\347\247\257.md" @@ -112,7 +112,10 @@ int main() { int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { - if (grid[i][j] == 1) count++; + if (grid[i][j] == 1){ + count++; + dfs(grid,i,j); + } } } cout << count << endl;