Graph 运行时错误:添加的无符号偏移量溢出 类解决方案{ 公众: 布尔isSafe(向量和图像、int sr、int sc、int初始值){ 如果(sr>=0&&sr=0&&sc矢量泛洪填充(矢量和图像。。。
由于是通过引用传递图像,因此不需要通过值返回图像 通过使用,您将大大提高性能Graph 运行时错误:添加的无符号偏移量溢出 类解决方案{ 公众: 布尔isSafe(向量和图像、int sr、int sc、int初始值){ 如果(sr>=0&&sr=0&&sc矢量泛洪填充(矢量和图像。。。,graph,backtracking,flood-fill,Graph,Backtracking,Flood Fill,由于是通过引用传递图像,因此不需要通过值返回图像 通过使用,您将大大提高性能 vector<vector<int>> floodFill(vector<vector<int>>& image, ... void泛光填充(矢量和图像、int-sr、int-sc、int-newColor){ int初始值=图像[sr][sc]; 图像[sr][sc]=新颜色; if(isSafe(图像,sr+1,sc,初始值)) { 泛光填充(图像,sr+1
vector<vector<int>> floodFill(vector<vector<int>>& image, ...
void泛光填充(矢量和图像、int-sr、int-sc、int-newColor){
int初始值=图像[sr][sc];
图像[sr][sc]=新颜色;
if(isSafe(图像,sr+1,sc,初始值))
{
泛光填充(图像,sr+1,sc,newColor);
}
if(isSafe(图像,sr-1,sc,初始值))
{
泛洪填充(图像,sr-1,sc,newColor);
}
if(isSafe(图像、sr、sc+1、初始值))
{
泛光填充(图像、sr、sc+1、新颜色);
}
if(isSafe(图像、sr、sc-1、初始值))
{
泛洪填充(图像,sr-1,sc,newColor);
}
}
使用调试器查找发生错误的WJ行
vector<vector<int>> floodFill(vector<vector<int>>& image, ...
void floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) {
int initial_value=image[sr][sc];
image[sr][sc]=newColor;
if(isSafe(image, sr+1, sc, initial_value))
{
floodFill( image, sr+1, sc, newColor);
}
if(isSafe(image, sr-1, sc, initial_value))
{
floodFill( image, sr-1, sc, newColor);
}
if(isSafe(image, sr, sc+1, initial_value))
{
floodFill( image, sr, sc+1, newColor);
}
if(isSafe(image, sr, sc-1, initial_value))
{
floodFill( image, sr-1, sc, newColor);
}
}