文件名称:FiveDirectionPad_Algo
介绍说明--下载内容来自于网络,使用问题请自行百度
此作業需使用Backtracking algorithm
從第一格開始,從1到9依序測試是否可以填入,若本來此格已有數字,則直接往下一格走。若可以填入( if(promising()) )則填入該數字並且往下一格移動繼續填,若此格沒有可填入的數字時,則結束該格的動作,回到上一格去測試剩下的可能結果。若已經填完( if(solution is found) ),則可能解+1,然後回到前面再繼續尋找接下來的可能解。直到全部可能的數字組合都試完之後,程式結束,所有可能解的個數也會被找到。需要印出的任一組解,則是另外開一個二維陣列去儲存,因為用外部檔案儲存會比較慢,加上陣列不大。Promising函數的內容為檢查是否可以在(row, col)填入num,檢查方法為
1.檢查同列中是否有相同數字
2.檢查同行中是否有相同數字
3.檢查其所屬的九宮格內是否有相同數字
若任依狀況成立,則num不能被填在(row, col)中,return false(0)
若以上狀況皆不成立,則num可被填在(row, col)中,return true(1)
然後為了避免程式運作太久(可行解數太多),所以我設了一個解的最大值MAX_SOLUTION來限制可以跑解的數量,若解太多則直接停止程式,並輸出”此題有超過MAX_SOLUTION組解”
-This operation need to use Backtracking algorithm
Starting from the first cell, from 1 to 9 can fill in the order of testing, if this box has had the number to go directly down a grid. If you can fill (if (promising ())) then enter the number and move down to fill a grid, if this is not to fill the number of cells, then the end of the cell movement, cell to return to the previous Test the remaining possible outcomes. If you already filled out (if (solution is found)), the solution may be+1, then back to front to continue looking for the next possible solution. Until all possible number combinations are tested after completing the program ended, all the possible number of solutions will be found. Any need to print a set of solutions is another to open a two-dimensional array to store, as an external file storage will be relatively slow, with the array small. Promising function to check whether the content can be (row, col) fill num, inspection methods
1. Check whether the same column
從第一格開始,從1到9依序測試是否可以填入,若本來此格已有數字,則直接往下一格走。若可以填入( if(promising()) )則填入該數字並且往下一格移動繼續填,若此格沒有可填入的數字時,則結束該格的動作,回到上一格去測試剩下的可能結果。若已經填完( if(solution is found) ),則可能解+1,然後回到前面再繼續尋找接下來的可能解。直到全部可能的數字組合都試完之後,程式結束,所有可能解的個數也會被找到。需要印出的任一組解,則是另外開一個二維陣列去儲存,因為用外部檔案儲存會比較慢,加上陣列不大。Promising函數的內容為檢查是否可以在(row, col)填入num,檢查方法為
1.檢查同列中是否有相同數字
2.檢查同行中是否有相同數字
3.檢查其所屬的九宮格內是否有相同數字
若任依狀況成立,則num不能被填在(row, col)中,return false(0)
若以上狀況皆不成立,則num可被填在(row, col)中,return true(1)
然後為了避免程式運作太久(可行解數太多),所以我設了一個解的最大值MAX_SOLUTION來限制可以跑解的數量,若解太多則直接停止程式,並輸出”此題有超過MAX_SOLUTION組解”
-This operation need to use Backtracking algorithm
Starting from the first cell, from 1 to 9 can fill in the order of testing, if this box has had the number to go directly down a grid. If you can fill (if (promising ())) then enter the number and move down to fill a grid, if this is not to fill the number of cells, then the end of the cell movement, cell to return to the previous Test the remaining possible outcomes. If you already filled out (if (solution is found)), the solution may be+1, then back to front to continue looking for the next possible solution. Until all possible number combinations are tested after completing the program ended, all the possible number of solutions will be found. Any need to print a set of solutions is another to open a two-dimensional array to store, as an external file storage will be relatively slow, with the array small. Promising function to check whether the content can be (row, col) fill num, inspection methods
1. Check whether the same column
(系统自动生成,下载前可以参看下载内容)
下载文件列表
FiveDirectionPad_Algo.cpp
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.