- 八皇后问题
尽力了,败在了对角线上
- 2024-1-24 11:25:03 @
#include<bits/stdc++.h>
using namespace std;
int q[8][8]={};
bool place(int t){
if(t%2) return false;
return true;
}
long s=0;
int main(){
system("color F1");
for(int a=0;a<8;a++){
q[0][a]=1;
for(int b=0;b<8;b++){
if(b!=a&&place(1)){
q[1][b]=1;
for(int c=0;c<8;c++){
if(c!=b&&c!=a&&place(2)){
q[2][c]=1;
for(int d=0;d<8;d++){
if(d!=c&&d!=b&&d!=a&&place(3)){
q[3][d]=1;
for(int e=0;e<8;e++){
if(e!=d&&e!=c&&e!=b&&e!=a&&place(4)){
q[4][e]=1;
for(int f=0;f<8;f++){
if(f!=e&&f!=d&&f!=c&&f!=b&&f!=a&&place(5)){
q[5][f]=1;
for(int g=0;g<8;g++){
if(g!=f&&g!=e&&g!=d&&g!=c&&g!=b&&g!=a&&place(6)){
q[6][g]=1;
for(int h=0;h<8;h++){
if(h!=g&&h!=f&&h!=e&&h!=d&&h!=c&&h!=b&&h!=a&&place(7)){
s++;
q[7][h]=1;
cout<<"No."<<s<<endl;
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
cout<<q[i][j];
}
cout<<endl;
}
q[7][h]=0;
}
}
q[6][g]=0;
}
}
q[5][f]=0;
}
}
q[4][e]=0;
}
}
q[3][d]=0;
}
}
}
}
q[1][b]=0;
}
}
q[0][a]=0;
}
return 0;
}
0 comments
No comments so far...
Information
- ID
- 699
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 151
- Accepted
- 43
- Uploaded By