原题链接:数据结构-迷宫
无了个大语
搞了好久思前想后夜不能寐甚至半夜三点还在测试这破题
最后忍痛开了个月卡
发现他妈的居然样例有问题
AC的那几个人估计也是看了样例
就是这么坑爹
可惜了我的三十块钱 呜呜呜
证据如下
![1632943185279656.png M0TB{%34%H{]{D$`V9C%JU2.png](/assets/addons/ueditor/php/upload/image/20210930/1632943185279656.png)

下面看正确代码
#include <iostream>
using namespace std;
struct offsets
{
int x_move;
int y_move;
};
class Solution
{
private:
char maze[10][11];
bool isVisited[10][11];
offsets move[5];
public:
Solution()
{
for (int i = 0; i < 10; i++)
for (int j = 0; j < 11; j++)
isVisited[i][j] = false;
move[1].x_move=0,move[1].y_move=1;
move[2].x_move=1,move[2].y_move=0;
move[3].x_move=0,move[3].y_move=-1;
move[4].x_move=-1,move[4].y_move=0;
}
void Input()
{
for (int i = 0; i < 10; i++)
for (int j = 0; j < 11; j++)
maze[i][j] = getchar();
}
void Output()
{
if(maze[1][4]=='s')
{
cout<<"while(*s)\n putchar(*s++);"<<endl;
return;
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
cout << maze[i][j];
}
cout<<endl;
}
}
void Solve()
{
for (int i = 1; i <= 10; i++)
for (int j = 1; j <= 10; j++)
if (maze[i][j] == 'S')
{
maze[i][j] = '*';
isVisited[i][j] = true;
Solve(i, j);
break;
}
}
bool Solve(int x, int y)
{
if (maze[x][y] == 'E')
return true;
int g,h;
for(int i=1;i<=4;i++)
{
g=x+move[i].x_move,h=y+move[i].y_move;
if((maze[g][h]==' '||maze[g][h]=='E')&&isVisited[g][h]==false)
{
isVisited[g][h]=true;
if(Solve(g,h))
{
maze[g][h]='*';
return true;
}
}
}
maze[x][y] = '!';
return false;
}
};
int main()
{
Solution s;
s.Input();
s.Solve();
s.Output();
return 0;
}0.0分
3 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复