蒟蒻求救!
  • 板块灌水区
  • 楼主osfly
  • 当前回复10
  • 已保存回复10
  • 发布时间2020/8/6 07:19
  • 上次更新2023/11/6 21:11:04
查看原帖
蒟蒻求救!
339299
osfly楼主2020/8/6 07:19

这个是蒟蒻的八皇后代码,求大佬帮忙!

#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)

2020/8/6 07:19
加载中...