csppass
连续 00 XP登录 / 注册
202244完善程序图的遍历与搜索提高+

洪水填充:⑤处应填

题目

完善程序:洪水填充(接上题)。 #include<bits/stdc++.h> using namespace std; const int ROWS = 8; const int COLS = 8; struct Point { int r, c; Point(int r, int c) : r(r), c(c) {} }; bool is_valid(char image[ROWS][COLS], Point pt, int prev_color, int new_color) { int r = pt.r; int c = pt.c; return (0 <= r && r < ROWS && 0 <= c && c < COLS && ① && image[r][c] != new_color); } void flood_fill(char image[ROWS][COLS], Point cur, int new_color) { queue<Point> queue; queue.push(cur); int prev_color = image[cur.r][cur.c]; ② ; while (!queue.empty()) { Point pt = queue.front(); queue.pop(); Point points[4] = { ③ , Point(pt.r - 1, pt.c), Point(pt.r, pt.c + 1), Point(pt.r, pt.c - 1)}; for (auto p : points) { if (is_valid(image, p, prev_color, new_color)) { ④ ; ⑤ ; } } } } ⑤处应填( )

考点拆解
算法思想与复杂度
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词