这个是蒟蒻的八皇后代码,求大佬帮忙!
#include <cstdio>
#include <cmath>
int g[8][8][92];
int temp[8];
int cnt;
bool judge;
void search(int top)
{
if(top == 7)
{
for(int p=0; p<8; p++) for(int q=0; q<8; q++) g[p][q][cnt]=0;
for(int p=0; p<8; p++) g[p][temp[p]][cnt]=1;
cnt++;
return ;
}
else
{
for(int i=0; i<8; i++)
{
judge=true;
for(int j=0; j<8; j++) if(temp[j]==i || (top-j)==abs(temp[j]-i)) judge=false;
if(judge)
{
temp[top]=i;
search(top+1);
}
}
}
return ;
}
int main()
{
search(0);
for(int i=0;i<92;i++)
{
printf("No. %d\n",i+1);
for(int j=0;j<8;j++)
{
for(int k=0;k<8;k++)
{
printf("%d",g[j][k][i]);
}
printf("\n");
}
}
}
输出全部错误(第一个错误,其他输出全部为0)