線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:864
推到 Plurk!
推到 Facebook!

騎士旅遊的問題

尚未結案
jakie720313
一般會員


發表:15
回覆:7
積分:4
註冊:2003-11-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-01 14:46:06 IP:61.230.xxx.xxx 未訂閱
各位大大,我有用遞迴方法寫出來這個程式,不過跑10*10就跑不動了@@ 我後來改用stack來寫,不過跑出來的結果是錯的,你們可以幫我看看哪裡錯了ㄇ? 倒數20到12行是判斷是否有解,我先把它列為註解,因為這個程式還是半成品,請問各位大大能幫幫我找出錯誤在哪ㄇ?順便幫我完成這個程式吧~~~感激不盡唷^^ #include #include #include #define N 20 int maze[N 2][N 2],mark[N 2][N 2]; int top=0; movea[8]={-2,-1,1,2,2,1,-1,-2}; moveb[8]={1,2,2,1,-1,-2,-2,-1}; typedef struct items { int x,y,dir; }knight; knight stack[N*N]; void push(knight s) { stack[top ]=s; } knight pop() { return(stack[top--]); } void main() { int i,j,d,g,h,a,k,range; int m,n,count=0; k=1; items temp; clrscr(); for(i=0;i=0)&&(h=0)&&maze[g][h]==0) { maze[g][h]=k; printf("%d %d = %d\n",g,h,k); getch(); temp.x=i; temp.y=j; temp.dir=a; push(temp); i=g; j=h; k ; count=0; break; } else count ; } if(count==8) { temp=pop(); i=temp.x; j=temp.y; a=temp.dir; g=i movea[a]; h=j moveb[a]; maze[g][h]=0; } } /* for(m=0;m
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-01 15:27:35 IP:140.135.xxx.xxx 未訂閱
jakie720313您好:    您該不會讓大家只由您的程式碼來知道您的題目為何吧< > 並請參考下面連結讓您的程式碼增加其閱讀性< > http://delphi.ktop.com.tw/topic.php?TOPIC_ID=41390 順心 發表人 -
jakie720313
一般會員


發表:15
回覆:7
積分:4
註冊:2003-11-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-12-02 01:43:56 IP:61.230.xxx.xxx 未訂閱
不好意思,忘記PO題目了~ A knight's tour of a chessboard (or any other grid) is a sequence of moves by a knight chess piece (which may only make moves which simultaneously shift one square along one axis and two along the other) such that each square of the board is visited exactly once. In this homework assignment, we assume that the knight begins with one of the four corners of the board. 8 possible moves 1 2 3 4 5 1 K8 K1 2 K7 K2 3 K 4 K6 K3 5 K5 K4 i之差值 j之差值 位置 K1 -2 1 (i-2,j 1) K2 -1 2 (i-1,j 2) K3 1 2 (i 1,j 2) K4 2 1 (i 2,j 1) K5 2 -1 (i 2,j-1) K6 1 -2 (i 1,j-2) K7 -1 -2 (i-1,j-2) K8 -2 -1 (i-2,j-1) Learn to use stack as the data structure programs. Learn to use backtracking 最主要就是要利用stack還有backtracking來寫這個程式,我上一篇po的程式碼有用到stack的POP跟PUSH不過結果還是有錯,好像錯在當8個方向都沒路的時候要走回去上一點的時候出錯了,請問哪裡有錯誤呢??
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-12-04 00:48:51 IP:140.135.xxx.xxx 未訂閱
jakie720313您好: 不知道下面聯結的討論是否和您的需求一樣 < href="http://delphi.ktop.com.tw/topic.php?TOPIC_ID=40972">http://delphi.ktop.com.tw/topic.php?TOPIC_ID=40972 順心 <>~我也是在學習的階段,回答的不好請您多多見諒與指教~
系統時間:2024-05-18 15:16:37
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!