本题解仅供参考,切勿模仿(思路和前排的人一样)
算法
(暴力枚举) $O(n!)$
blablabla
时间复杂度分析:blablabla
C++ 代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int _________ = 15;
int _____;
char _[_________][_________];
bool __[_________], ___[_________], ____[_________];
void ___________()
{
for (int ______ = 1; ______ <= _____; ______++)
{
for (int _______ = 1; _______ <= _____; _______++)
printf("%c", _[______][_______]);
puts("");
}
puts("");
}
int __________(int ________)
{
if (________ > _____)
{
___________();
return 0;
}
for (int ______ = 1; ______ <= _____; ______++)
if (!__[______] && !___[________ + ______] && !____[_____ - ________ + ______])
{
_[________][______] = 'Q';
__[______] = ___[________ + ______] = ____[_____ - ________ + ______] = true;
__________(________ + 1);
__[______] = ___[________ + ______] = ____[_____ - ________ + ______] = false;
_[________][______] = '.';
}
}
int main()
{
scanf("%d", &_____);
for (int ______ = 1; ______ <= _____; ______ ++ )
for (int _______ = 1; _______ <= _____; _______ ++ )
_[______][_______] = '.';
__________(1);
return 0;
}