日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > 華為面試題:迷宮問題 C語言源碼

華為面試題:迷宮問題 C語言源碼

來源:程序員人生   發布時間:2015-04-08 08:43:50 閱讀次數:4327次

定義1個2維數組N*M(其中2<=N<=10;2<=M<=10),如5 × 5數組下所示:


int maze[5][5] = {


        0, 1, 0, 0, 0,


        0, 1, 0, 1, 0,


        0, 0, 0, 0, 0,


        0, 1, 1, 1, 0,


        0, 0, 0, 1, 0,


};


它表示1個迷宮,其中的1表示墻壁,0表示可以走的路,只能橫著走或豎著走,不能斜著走,要求編程序找出從左上角到右下角的最短線路。入口點為[0,0],既第1空格是可以走的路。

Input

1個N × M的2維數組,表示1個迷宮。數據保證有唯1解,不斟酌有多解的情況,即迷宮只有1條通道。

Output

左上角到右下角的最短路徑,格式如樣例所示。

5 5
0 1 0 0 0
0 1 0 1 0
0 0 0 0 0
0 1 1 1 0
0 0 0 1 0
輸出
(0,0)
(1,0)
(2,0)
(2,1)
(2,2)
(2,3)
(2,4)
(3,4)
(4,4)

#include "stdio.h" #include "stdlib.h" #include "string.h" #define MAX_PATH 256 int maze[10][10] = {0}; int route[100][2] = {0}; int main() { int row=0,line=0; scanf("%d %d",&row,&line); for (int i=0;i<row;i++) { for (int j=0;j<line;j++) { scanf("%d",&maze[i][j]); } } //走迷宮 //堆棧:記錄上1個位置 int xcurrent = 0; int ycurrent = 0; int count=0; while(true) { if (maze[xcurrent+1][ycurrent]==0 && xcurrent+1<row) { //返回上1個位置 if (route[count⑴][0]==xcurrent+1 && route[count⑴][1]==ycurrent) { maze[xcurrent][ycurrent]=1;//設置為墻 count--; xcurrent++; } else { route[count][0]=xcurrent; route[count][1]=ycurrent; count++; xcurrent++; } } else if (maze[xcurrent][ycurrent+1]==0 && ycurrent<line) { if (route[count⑴][0]==xcurrent && route[count⑴][1]==ycurrent+1) { maze[xcurrent][ycurrent]=1;//設置為墻 count--; ycurrent++; } else { route[count][0]=xcurrent; route[count][1]=ycurrent; count++; ycurrent++; } } else if (maze[xcurrent⑴][ycurrent]==0 && xcurrent⑴>=0) { if (route[count⑴][0]==xcurrent⑴ && route[count⑴][1]==ycurrent) { maze[xcurrent][ycurrent]=1;//設置為墻 count--; xcurrent--; } else { route[count][0]=xcurrent; route[count][1]=ycurrent; count++; xcurrent--; } } else if (maze[xcurrent][ycurrent⑴]==0 && ycurrent⑴>=0) { if (route[count⑴][0]==xcurrent && route[count⑴][1]==ycurrent⑴) { maze[xcurrent][ycurrent]=1;//設置為墻 count--; ycurrent--; } else { route[count][0]=xcurrent; route[count][1]=ycurrent; count++; ycurrent--; } } if (xcurrent==row⑴ && ycurrent==line⑴) { route[count][0]=xcurrent; route[count][1]=ycurrent; count++; break; } } for (int i=0;i<count;i++) { printf("(%d,%d) ",route[i][0],route[i][1]); } return 0; }


 

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美精品一区二区在线观看 | 国产精品午夜视频 | 男女国产视频 | 91.成人天堂一区 | 9久久精品 | 黄色片网站免费观看 | 久久99精品久久久久 | 亚洲三级网站 | 国产精品久久久久久久久久大牛 | 三级毛片视频网站 | 天天艹| av网站大全在线观看 | 精品中文字幕一区二区三区 | 国产精品免费在线 | 91久久国产综合久久 | 亚洲+变态+欧美+另类+精品 | 国产激情视频在线 | 日韩精品免费一区二区夜夜嗨 | 四季av一区二区三区免费观看 | 综合五月婷 | 国产黄在线 | 国产高清精品一区二区三区 | 久久久久亚洲av成人毛片韩 | 欧美黑人极品猛少妇色xxxxx | 一级毛片免费播放 | 国产精品13p | 日本国产中文字幕 | 亚洲成人av在线播放 | 91麻豆精品一区二区三区 | 二区在线视频 | 在线一区二区三区做爰视频网站 | 91亚洲精品一区二区 | 懂色av蜜乳av一二三区 | 日本a黄| 精品欧美一区二区三区免费观看 | 色免费在线视频 | 18av在线播放| 久久精品国产亚洲一区二区三区 | 91午夜视频 | 这里有精品视频 | 成人免费一区二区三区视频网站 |