@[shooting__star](/user/955954) 对角线的标记写错了
by Luka__Modric @ 2024-02-22 21:55:41
```cpp
#include<bits/stdc++.h>
using namespace std;
int n;
int cnt;
int mp[20][20];
int vis[20][20];
void dfs(int ans)
{
if(ans==n)
{
cnt++;
if(cnt<=3)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(mp[i][j]==1)
cout<<j+1<<' ';
}
}
cout<<endl;
}
return;
}
for(int i=0;i<n;i++)
{
if(vis[ans][i]==0)
{
mp[ans][i]=1;
for(int j=0;j<n;j++)
{
vis[ans][j]=1;
}
for(int j=0;j<n;j++)
{
vis[j][i]=1;
}
int x=ans;
for(int j=i;j>=0;j--)
{
vis[x][j]=1;
x++;
}
x=ans-1;
for(int j=i+1;j<n;j++)
{
vis[x][j]=1;
x--;
}
x=ans;
for(int j=i;j<n;j++)
{
vis[x][j]=1;
x++;
}
x=ans;
for(int j=i-1;j>=0;j++)
{
vis[x][j]=1;
x--;
}
dfs(ans+1);
mp[ans][i]=0;
for(int j=0;j<n;j++)
{
vis[ans][j]=0;
}
for(int j=0;j<n;j++)
{
vis[j][i]=0;
}
x=ans;
for(int j=i;j>=0;j--)
{
vis[x][j]=0;
x++;
}
x=ans-1;
for(int j=i+1;j<n;j++)
{
vis[x][j]=0;
x--;
}
x=ans;
for(int j=i;j<n;j++)
{
vis[x][j]=0;
x++;
}
x=ans;
for(int j=i-1;j>=0;j++)
{
vis[x][j]=0;
x--;
}
}
}
}
int main()
{
cin>>n;
dfs(0);
cout<<cnt;
return 0;
}
```
好家伙直接爆了
by shooting__star @ 2024-02-22 22:01:17
@[shooting__star](/user/955954) 你中间x会剪成<0或者>n的吧
by Luka__Modric @ 2024-02-22 22:08:24
@[shooting__star](/user/955954) 还有你这对角线标记怎么只有两支啊,不应该有四支吗
by Luka__Modric @ 2024-02-22 22:08:52
?这是什么神秘写法
by Yzmddsw @ 2024-02-22 22:16:55
其实你可以在每一次放棋的时候判断一下这个点能不能下棋就可以了。
by Yzmddsw @ 2024-02-22 22:18:39