vvhungtam
Tổng số bài gửi : 11 Registration date : 16/09/2007
| Tiêu đề: Ma Di Tuan 5/5/2008, 10:40 | |
| - Code:
-
//Ma di tuan_Vo Van Hung Tam #include <iostream> #include <iomanip> using namespace std;
const max=8; int a[max][max],lan=0; int x[]={-2,-1,1,2,2,1,-1,-2}; int y[]={1,2,2,1,-1,-2,-2,-1}; void print () { cout<<"Truong Hop Thu: "<<++lan<<endl; for (int i=0; i < max; i++) { for (int j=0; j < max; j++) cout<<setw(3)<<a[i][j]; cout<<endl; } cout<<endl; }
void thu(int dem,int i,int j) { int b,c,k; for (k=0;k<max;k++) { b=i+x[k];c=j+y[k]; if (a[b][c]==0 && (0<=b && b<8) && (0<=c && c<8)) { a[b][c]=++dem; if (dem<max*max) thu(dem,b,c); else print(); dem--; a[b][c]=0; } } }
void tim() { for (int i=0; i<max; i++) for (int j=0; j<max;j++) { a[i][j]=1; thu(1,i,j); } }
int main() { tim(); return 0; }
| |
|