EightQueens in the game of chess
2008-04-27 21:24
197 查看
国际象棋八皇后相容排阵问题:
My code of today
#include <iostream.h>
//八皇后求解
int k=0,result[10]={0};
int main()
{
void search();
void shresult();
search();
return(0);
}
//Show the result
void shresult()
{
for(k=0;k<8;k++) cout<<result[k]<<',';
cout<<"/t OK"<<endl;
}
//Searching the answer for the problem.
void search()
{
int i,j,judge;
for(i=0;i<8;i++)
{
judge=1;
for(j=0;j<k;j++)
{
if(i==result[j]) judge&=0;
if(i==(result[j]-k+j)) judge&=0;
if(i==(result[j]+k-j)) judge&=0;
}
if(judge){result[k]=i;k++;search();}
}
if(!(k<8)) shresult();
k--;
}
My code of today
#include <iostream.h>
//八皇后求解
int k=0,result[10]={0};
int main()
{
void search();
void shresult();
search();
return(0);
}
//Show the result
void shresult()
{
for(k=0;k<8;k++) cout<<result[k]<<',';
cout<<"/t OK"<<endl;
}
//Searching the answer for the problem.
void search()
{
int i,j,judge;
for(i=0;i<8;i++)
{
judge=1;
for(j=0;j<k;j++)
{
if(i==result[j]) judge&=0;
if(i==(result[j]-k+j)) judge&=0;
if(i==(result[j]+k-j)) judge&=0;
}
if(judge){result[k]=i;k++;search();}
}
if(!(k<8)) shresult();
k--;
}
相关文章推荐
- The Use of Design Patterns In Game Development
- ORA-30926: unable to get a stable set of rows in the source tables
- bundle install时候出现"Could not find modernizr-2.6.2 in any of the sources"
- 方法数超过64K:The number of method references in a .dex file cannot exceed 64K.
- python: find the index of a given value in a list
- How to get the length of array of strings in C? - Yahoo! Answers
- The war of the world-----The war in my heart
- The package does not support the device architecture (x86). You can change the supported architectures in the Android Build section of the Project Opt
- How to troubleshoot the performance of Ad-Hoc queries in SQL Server [ZT-from MS]
- The Role of Delegation Tokens in Apache Hadoop Security
- POJ 3688 Cheat in the Game(博弈论)
- A cycle was detected in the build path of project
- 让人哭笑不得的“Unable to load one or more of the types in the assembly”问题的解决!
- Overlook the localization of resource in compiling
- quick count the number of the rows in a big table
- The number of method references in a .dex file cannot exceed 64K.
- How do you get the length of a string in jQuery?
- Codeforces 451C Predict Outcome of the Game(暴力)
- 【MongoDB】The basic operation of Index in MongoDB
- UserWarning: The installed version of numexpr 2.4 is not supported in pandas and will be not be used