CPU糊透的未解之谜
查看原帖
CPU糊透的未解之谜
811437
littlewhite_楼主2024/7/21 21:43

不知道是评测机问题还是代码问题

我是想不出来为啥,有没有大佬帮我看看QAQ

评测记录:

可以看到,4号~10号测试数据是WA

然后我下载了4号数据

4号数据及本机结果:

一模一样!!!

上代码,求调QAQ:

#include <bits/stdc++.h>
using namespace std;

int n, ans=0;
int a[9], b[9], c[18], d[18];

void print()
{
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (a[i] == j)
				cout << j << " ";
		}
	}
	cout << endl;
}

void search(int i)
{
	for (int j = 1; j <= n; j++)
	{
		if (b[j] == 0 && c[i - j + 7] == 0 && d[i + j] == 0)
		{
			a[i] = j;
			b[j] = 1;
			c[i - j + 7] = 1;
			d[i + j] = 1;
			if (i == n)
			{
				++ans;
				if(ans<=3)print();
			}
			else
				search(i + 1);
			b[j] = 0;
			c[i - j + 7] = 0;
			d[i + j] = 0;
		}
	}
}

int main()
{
	cin >> n;
	search(1);
	cout << ans;
	return 0;
} 
2024/7/21 21:43
加载中...