Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
nei.cpp
Package: knight.rar [view]
Upload User: cctqzzy
Upload Date: 2020-11-17
Package Size: 1k
Code Size: 2k
Category:
Compress-Decompress algrithms
Development Platform:
Visual C++
- #include<iostream>
- using namespace std;
- int row[8]={-1,-2,-2,-1,1,2,2,1,}; /*8个方向上的x增量*/
- int col[8]={2,1,-1,-2,-2,-1,1,2}; /*8个方向上的y增量*/
- int h[8][8]; /*记录走的路径*/
- int num; /*记录方案个数*/
- void coutSolution();
- void try1(int x,int y,int i);
- int main()
- {
- int row,col;
- num=0;
- for(row=0;row<=7;row++)
- for(col=0;col<=7;col++)
- h[row][col]=0;
- int m,n;
- cout<<"输入骑士最开始的位置行:列:";
- cin>>m;
- cin>>n;
- h[m-1][n-1]=1;
- //h[0][0]=1;
- try1(m-1,n-1,2);
- /*输出总方案数*/
- cout<<"总方案数为%d"<<num;
- //system("pause");
- return 0;
- }
- /*从(x,y)出发,为第i步找合适位置*/
- void try1(int x,int y,int i)
- {
- int dir,u,v;
- if (i>64) /*已经走完64步,则统计方案个数,打印方案,跳出递归*/
- {
- num++;
- if(num==1)
- coutSolution();
- }
- else
- for(dir=0;dir<=7;dir++) /*依次试遍8个方向*/
- {
- u=x+row[dir]; /*得到的新坐标*/
- v=y+col[dir];
- if ((u>=0) && (u<=7) && (v>=0) && (v<=7) && (h[u][v]==0))/*如果新坐标在棋盘上,并且这一格可以走*/
- {
- h[u][v]=i;/*占据位置[u,v]*/
- try1(u,v,i+1);
- h[u][v]=0;
- }
- }
- }
- /*打印方案*/
- void coutSolution()
- {
- int row,col;
- for(row=0;row<=7;row++)
- {
- for(col=0;col<=7;col++)
- cout<<h[row][col]<<' ';
- cout<<"n";
- }
- cout<<"nn";
- }