Logo
Section 1 / 8

谁应该参加本课程以及原因是什么?

了解本课程的目标受众、编程语言及学习成果。

导入

谁应该参加本课程以及原因是什么?

了解本课程的目标受众、编程语言及学习成果。

1#include <iostream> 2#include <vector> 3#include <string> 4 5// 假设已定义 ColoredGrid 和 BinaryTree 类 6class ColoredGrid { 7public: 8 int rows, columns; 9 std::vector<std::vector<int>> grid; 10 11 ColoredGrid(int r, int c) : rows(r), columns(c) { 12 grid.resize(rows, std::vector<int>(columns, 0)); 13 } 14 15 // 获取指定位置的单元格 16 int& operator()(int row, int col) { 17 return grid[row][col]; 18 } 19 20 // 计算距离并设置为起点的距离 21 void setDistances(int startRow, int startCol) { 22 // 这里应实现基于 BFS 或类似算法的距离计算逻辑 23 // 为简化,仅占位 24 } 25 26 // 转换为 PNG 图像(模拟) 27 void toPNG(const std::string& filename) { 28 std::cout << "Saving image to: " << filename << std::endl; 29 // 实际图像生成逻辑需依赖外部库如 stb_image_write 30 } 31}; 32 33class BinaryTree { 34public: 35 static void on(ColoredGrid& grid) { 36 // 模拟二叉树迷宫生成逻辑 37 std::cout << "Generating maze using BinaryTree algorithm..." << std::endl; 38 // 实际实现包括随机遍历和墙拆除等操作 39 } 40}; 41 42int main() { 43 ColoredGrid grid(25, 25); 44 BinaryTree::on(grid); 45 46 int startRow = grid.rows / 2; 47 int startCol = grid.columns / 2; 48 grid.setDistances(startRow, startCol); 49 50 grid.toPNG("colorized.png"); 51 52 return 0; 53}

入门