请在 下方输入 要搜索的题目:

有一间长方形的房子,地上铺了红色、黑色两种颜色的正方形瓷砖。你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动。请写一个程序,计算你总共能够到达多少块黑色的瓷砖。

有一间长方形的房子,地上铺了红色、黑色两种颜色的正方形瓷砖。你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动。请写一个程序,计算你总共能够到达多少块黑色的瓷砖。

发布时间:2025-06-22 19:47:12
推荐参考答案 ( 由 快搜搜题库 官方老师解答 )
联系客服
答案:答:#include using namespace std;//宏定义增强代码适应能力和可读性#define MAX 22//方块四周加白色块,去掉边界判断,//使得递归统一终止于白色块char rect[MAX][MAX];//返回从某点走过的格子数,减少全局量的使用int walkFrom(int currentRow, int currentCol);void main(){int col, row;while(cin >> col >> row, col!=0 && row != 0){int i, j, startRow, startCol;//intializefor(i = 0; i < MAX; i )for(j=0; j> rect[i][j];if(rect[i][j] == '@'){startRow = i;startCol = j;rect[i][j]='.';}}cout << walkFrom(startRow,startCol) << endl;}//while}int walkFrom(int currentRow, int currentCol){if(rect[currentRow][currentCol] == '#')return 0;else rect[currentRow][currentCol] = '#';return1 walkFrom(currentRow 1,currentCol) walkFrom(currentRow-1,currentCol) walkFrom(currentRow,currentCol 1) walkFrom(currentRow,currentCol-1) ;}
专业技术学习
专业技术学习
搜搜题库系统