91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

【問題描述】 騎士巡游問題:從國際象棋棋盤上任意給定的方格開始移動騎士,相繼地到達所有的64個方格,進入每個方格一次且僅進入一次。

資源截圖

代碼片段和文件信息

#include???
#include???
using?namespace?std;??
const?int?n?=?8;????//n*n的棋盤??
int?a[n+1][n+1];????//二維數組表示棋盤,不使用0行0列??
int?move[9][3];?????//移動偏移量(增量)。為方便起見,只使用其中1-8行、1-2列(不用0行0列)??
bool?possible;??????//是否擺放成功??
void?go(int?i?int?j?int?k?bool?&possible)??
{??
????/*從(ij)點出發,做第k至第n*n次的移動?
??????若成功則通過引用參數q返回true*/??
????int?v?=?0gh;??//v(取值1-8)表示方向,(gh)表示從當前點(ij)沿v方向移動后到達點的坐標??
????do??
????{??
????????v++;??
????????possible?=?false;??
????????g?=?i?+?move[v][1];??
????????h?=?j?+?move[v][2];??
????????if?(g?>=?1?&&?g?<=?n?&&?h?>=?1?&&?h?<=?n?&&?a[g][h]?==?0)???//(gh)處于棋盤內,且尚未放過棋子??
????????{??
????????????a[g][h]?=?k;????//將第k步棋子放在(gh)點??
????????????if?(k?????????????{??
????????????????go(ghk+1possible);???//遞歸調用??
????????????????if(!possible)??//如果找不到解,利用回溯法把數組都賦0值
????????????????????a[g][h]?=?0;??
????????????}??
????????????else????//放滿整個棋盤,possible返回true??
????????????????possible?=?true;??
????????}??
????}??
????while(!possible?&&?(v?!=?8));?//循環的條件是possible為false(因為沒有找到最后解之前possible都為false),并且v不為8表示沒有遍歷所有方向?
}??
int?main()??
{??
????//初始化move數組??
????move[1][1]?=?2;?????move[1][2]?=?1;???
????move[2][1]?=?1;?????move[2][2]?=?2;??
????move[3][1]?=?-1;????move[3][2]?=?2;??
????move[4][1]?=?-2;????move[4][2]?=?1;??
????move[5][1]?=?-2;????move[5][2]?=?-1;??
????move[6][1]?=?-1;????move[6][2]?=?-2;??
????move[7][1]?=?1;?????move[7][2]?=?-2;??
????move[8][1]?=?2;?????move[8][2]?=?-1;??
????cout?<????int?x1y1;??
????cin?>>?x1?>>?y1;????//輸入初始坐標??
????a[x1][y1]?=?1;??????//在棋盤(x1y1)處放下棋子(第1步棋)??
????go(x1?y1?2?possible);????//從(x1y1)出發,做第2至第25次的移動,若成功possible返回true??
????//若擺放成功,輸出棋盤(移動過程)??
????if?(possible)??
????????for?(int?i?=?1;?i?<=?n;?i++)??
????????{??
????????????for?(int?j?=?1;?j?<=?n;?j++)??
????????????????cout?<????????????cout?<????????}??
????else????//擺放不成功??
????????cout?< system(“pause“);
????return?0;??
}??

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????38912??2010-12-09?15:51??Knight\Debug\Knight.exe

?????文件?????394952??2010-12-09?15:51??Knight\Debug\Knight.ilk

?????文件?????584704??2010-12-09?15:51??Knight\Debug\Knight.pdb

?????文件???????7120??2010-12-09?15:51??Knight\Knight\Debug\BuildLog.htm

?????文件????????663??2010-12-09?15:07??Knight\Knight\Debug\Knight.exe.embed.manifest

?????文件????????728??2010-12-09?15:07??Knight\Knight\Debug\Knight.exe.embed.manifest.res

?????文件????????621??2010-12-09?15:51??Knight\Knight\Debug\Knight.exe.intermediate.manifest

?????文件??????41010??2010-12-09?15:51??Knight\Knight\Debug\Knight.obj

?????文件?????????69??2010-12-09?15:51??Knight\Knight\Debug\mt.dep

?????文件?????166912??2010-12-09?15:51??Knight\Knight\Debug\vc90.idb

?????文件?????217088??2010-12-09?15:51??Knight\Knight\Debug\vc90.pdb

?????文件???????2357??2010-12-09?15:51??Knight\Knight\Knight.cpp

?????文件???????3934??2010-12-09?15:06??Knight\Knight\Knight.vcproj

?????文件???????1417??2010-12-09?15:58??Knight\Knight\Knight.vcproj.CHENGXIONG.Administrator.user

?????文件????1166336??2010-12-09?15:58??Knight\Knight.ncb

?????文件????????884??2010-12-09?15:06??Knight\Knight.sln

????..A..H.??????8192??2010-12-09?15:58??Knight\Knight.suo

?????目錄??????????0??2010-12-09?15:51??Knight\Knight\Debug

?????目錄??????????0??2010-12-09?15:09??Knight\Debug

?????目錄??????????0??2010-12-09?15:51??Knight\Knight

?????目錄??????????0??2010-12-09?15:07??Knight

-----------?---------??----------?-----??----

??????????????2635899????????????????????21


評論

共有 條評論