c语言迷宫问题 急求
实验内容:迷宫的队实现。要求构建校园地图(如下),输入任意的起点终点,可以指出一条路径。迷宫(及路径)的图形化参见下文。intmaze[14][28]=//迷宫举例:校园...
实验内容:迷宫的队实现。要求构建校园地图(如下),输入任意的起点终点,可以指出一条路径。迷宫(及路径)的图形化参见下文。
int maze[14][28]= //迷宫举例:校园地图
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,
1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
for(i=0;i<14;i++) //迷宫图形化输出
{
for(j=0;j<28;j++)
{
if(maze[i][j]==1)
cout<<"■";
else cout<<"□";
}
cout<<endl;
}
就是这样。。语言0基础 上来就留了这么个作业 求助 展开
int maze[14][28]= //迷宫举例:校园地图
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,
1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
for(i=0;i<14;i++) //迷宫图形化输出
{
for(j=0;j<28;j++)
{
if(maze[i][j]==1)
cout<<"■";
else cout<<"□";
}
cout<<endl;
}
就是这样。。语言0基础 上来就留了这么个作业 求助 展开
2个回答
展开全部
1是路径还是0是路径?
#include<cstdio>
#include<cstdlib>
enum se{
path,
block,
end,
mark
};
struct way{
int x;
int y;
}record[1000];
int maze[14][28]={
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,
1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
void set_end(int ex, int ey){ //设置结束
maze[ex][ey] = end;
}
void printMaze(){
for(int i=0;i<14;i++) //迷宫图形化输出
{
for(int j=0;j<28;j++)
{
if(maze[i][j] == block)
printf("■");
else printf("□");
}
printf("\n");
}
}
void printResult(int length){
for(int i = 0; i < 14; i++) //迷宫路径图形化输出
{
for(int j = 0; j < 28; j++)
{
if(maze[i][j] == mark)
printf(">>");
else if(maze[i][j] == block)
printf("■");
else if(maze[i][j] == end)
printf("<<");
else if(maze[i][j] == path)
printf("□");
}
printf("\n");
}
for(int x = 0; x < length - 1; x++){
printf("<%d,%d> ->", record[x].x, record[x].y);
}
printf("<%d,%d> ", record[x].x, record[x].y);
printf("\n");
}
void search_path(int x, int y, int length){ // 递归寻找路径
if(maze[x][y] == end){
printResult(length);
system("pause");
exit(0);
}
else{
if(maze[x + 1][y] != block && maze[x + 1][y] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x + 1, y, length);
maze[x][y] = path;
length --;
}
if(maze[x - 1][y] != block && maze[x - 1][y] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x - 1, y, length);
maze[x][y] = path;
length --;
}
if(maze[x][y + 1] != block && maze[x][y + 1] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x, y + 1, length);
maze[x][y] = path;
length --;
}
if(maze[x][y - 1] != block && maze[x][y - 1] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x, y - 1, length);
maze[x][y] = path;
length --;
}
return;
}
}
int main(void)
{
set_end(12,26);
printMaze();
search_path(1,5,0);
printf("no path!"); //没有路径
return 0;
}
#include<cstdio>
#include<cstdlib>
enum se{
path,
block,
end,
mark
};
struct way{
int x;
int y;
}record[1000];
int maze[14][28]={
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,
1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
void set_end(int ex, int ey){ //设置结束
maze[ex][ey] = end;
}
void printMaze(){
for(int i=0;i<14;i++) //迷宫图形化输出
{
for(int j=0;j<28;j++)
{
if(maze[i][j] == block)
printf("■");
else printf("□");
}
printf("\n");
}
}
void printResult(int length){
for(int i = 0; i < 14; i++) //迷宫路径图形化输出
{
for(int j = 0; j < 28; j++)
{
if(maze[i][j] == mark)
printf(">>");
else if(maze[i][j] == block)
printf("■");
else if(maze[i][j] == end)
printf("<<");
else if(maze[i][j] == path)
printf("□");
}
printf("\n");
}
for(int x = 0; x < length - 1; x++){
printf("<%d,%d> ->", record[x].x, record[x].y);
}
printf("<%d,%d> ", record[x].x, record[x].y);
printf("\n");
}
void search_path(int x, int y, int length){ // 递归寻找路径
if(maze[x][y] == end){
printResult(length);
system("pause");
exit(0);
}
else{
if(maze[x + 1][y] != block && maze[x + 1][y] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x + 1, y, length);
maze[x][y] = path;
length --;
}
if(maze[x - 1][y] != block && maze[x - 1][y] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x - 1, y, length);
maze[x][y] = path;
length --;
}
if(maze[x][y + 1] != block && maze[x][y + 1] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x, y + 1, length);
maze[x][y] = path;
length --;
}
if(maze[x][y - 1] != block && maze[x][y - 1] != mark){
maze[x][y] = mark;
record[length].x = x;
record[length].y = y;
length++;
search_path(x, y - 1, length);
maze[x][y] = path;
length --;
}
return;
}
}
int main(void)
{
set_end(12,26);
printMaze();
search_path(1,5,0);
printf("no path!"); //没有路径
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
int main(){
int maze[14][28]= //迷宫举例:校园地图
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,
1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,1,0,1,1,1,1,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0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,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
int i,j;
for(i=0;i<14;i++) //迷宫图形化输出
{
for(j=0;j<28;j++)
{
if(maze[i][j]==1)
cout<<"■";
else cout<<"□";
}
cout<<endl;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询