Re: [討論] 男人應該要有夢想嗎?平凡一生?

看板MenTalk (男人話題)作者 (meowyih)時間13年前 (2012/09/14 09:23), 編輯推噓4(402)
留言6則, 4人參與, 最新討論串10/11 (看更多)
※ 引述《NoPTT (貧乏神入侵!)》之銘言: : ┌─────────────────────────────────────┐ : │ 文章代碼(AID): #1GK6oiUb (joke) [ptt.cc] [kuso] 日本未來館教育動畫 │ : │ 文章網址: http://www.ptt.cc/bbs/joke/M.1347447980.A.7A5.html │ : │ 這一篇文章值 411 Ptt幣 │ : └─────────────────────────────────────┘ : 這才叫做夢想! : スーパーコンピュータ! : 不離不棄! 科學少女啊!

09/13 16:46,
有沒有數學公式去計算這個問題?
09/13 16:46

09/13 16:46,
哪位強者提供,讓我玩玩
09/13 16:46
雖然我沒有要提供公式, 但是我可以把這位大姊姊寫的程式分享給大家。XD 下面是用 C 寫的版本,如果需要 Java 或其他語言的請自己改囉。 (有人真的要丟給超級電腦跑跑看嗎? :p) #include <stdio.h> #include <stdlib.h> /* * Find the all paths from node 0 to node 8. * Using stupid tree traversal algorithm. haha :D * * 0 --- 1 --- 2 * | | | * 3 --- 4 --- 5 * | | | * 6 --- 7 --- 8 */ #define START_NODE 0 #define END_NODE 8 #define NUMBER_OF_NODE 9 /* if mPath[n][m] == 1. there is a path between n and m */ static int mPath[NUMBER_OF_NODE][NUMBER_OF_NODE] = { /* 0 1 2 3 4 5 6 7 8 */ /* 0 */ { 0, 1, 0, 1, 0, 0, 0, 0, 0 }, /* 1 */ { 1, 0, 1, 0, 1, 0, 0, 0, 0 }, /* 2 */ { 0, 1, 0, 0, 0, 1, 0, 0, 0 }, /* 3 */ { 1, 0, 0, 0, 1, 0, 1, 0, 0 }, /* 4 */ { 0, 1, 0, 1, 0, 1, 0, 1, 0 }, /* 5 */ { 0, 0, 1, 0, 1, 0, 0, 0, 1 }, /* 6 */ { 0, 0, 0, 1, 0, 0, 0, 1, 0 }, /* 7 */ { 0, 0, 0, 0, 1, 0, 1, 0, 1 }, /* 8 */ { 0, 0, 0, 0, 0, 1, 0, 1, 0 }, }; /* print the workable path */ void printRecord( int *record ); /* recurrsive method to travesal all paths */ void goNextNode( int* record ); int main() { /* prepare and init the record */ int *record = (int*) malloc( sizeof(int)*NUMBER_OF_NODE ) ; for ( int i = 0; i < NUMBER_OF_NODE; i ++ ) record[i] = -1; record[0] = START_NODE; /* start node 0 */ goNextNode( record ); return 0; } void printRecord( int *record ) { for ( int i = 0; i < NUMBER_OF_NODE; i ++ ) { if ( record[i] >= 0 ) printf( "%d", record[i] ); else break; } printf("\r\n"); return; } void goNextNode( int* record ) { int idx; int currentNode = -1; int currentNodeInRecordPosition = -1; bool isVisited = false; /* find current node */ for ( idx = 0; idx < NUMBER_OF_NODE; idx ++ ) { if ( record[idx] >= 0 ) { currentNode = record[idx]; currentNodeInRecordPosition = idx; } else { break; } } /* check if we reach the final */ if ( currentNode == END_NODE ) { printRecord( record ); free( record ); return; } /* find next available node */ for ( idx = 0; idx < NUMBER_OF_NODE; idx ++ ) { if ( mPath[currentNode][idx] == 1 ) { /* find if such node was already visited before */ isVisited = false; for ( int j = 0; j < currentNodeInRecordPosition; j ++ ) { if ( record[j] == idx ) { isVisited = true; } } if ( isVisited ) continue; /* "idx" is an available node that didn't vivist before */ int *newRecord = (int*)malloc( sizeof(int)*NUMBER_OF_NODE ); for ( int j = 0; j < NUMBER_OF_NODE; j ++ ) newRecord[j] = record[j]; newRecord[currentNodeInRecordPosition+1] = idx; goNextNode( newRecord ); } } free( record ); return; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.57.131.72

09/14 10:50, , 1F
我最討厭寫程式了 但是又很欽佩很會寫C++的人 XD
09/14 10:50, 1F

09/14 11:27, , 2F
大叔你...太誇張了吧 orz
09/14 11:27, 2F

09/14 11:28, , 3F
這個要怎麼用啊 ? 小弟外行
09/14 11:28, 3F
這郭有點難在幾行內回答捏, 如果你是正妹我可以到府免費當你的 C/C++/Java 或是 Android/iOS/Win32 家教, 可惜正妹對這些都沒興趣 T_T (笑)

09/14 11:32, , 4F
去載個Dev C丟進去Run
09/14 11:32, 4F
※ 編輯: meowyih 來自: 61.57.131.72 (09/14 18:11)

09/15 00:00, , 5F
這個真像老鼠走迷宮,但是是拿來算有幾種Path,還是放過我家
09/15 00:00, 5F

09/15 00:00, , 6F
的省電型PC好了 囧
09/15 00:00, 6F
文章代碼(AID): #1GKeRqf5 (MenTalk)
討論串 (同標題文章)
文章代碼(AID): #1GKeRqf5 (MenTalk)