绿豆沙 @ 2023-07-19 22:04:00
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000001;
int vis[2][maxn];
int c[maxn];
int tot=0,n;
void dfs(int cur){
if(cur>n){
if(tot<=2){
for(int i=1;i<=n;i++){
cout<<c[i]<<" ";
}
cout<<endl;
}
tot++;
}
else for(int i=1;i<=n;i++){
if(!vis[0][i]&&!vis[1][cur+i]&&!vis[2][cur-i+n]){
c[cur]=i;
vis[0][i]=vis[1][cur+i]=vis[2][cur-i+n]=1;
dfs(cur+1);
vis[0][i]=vis[1][cur+i]=vis[2][cur-i+n]=0;
}
}
return;
}
int main(){
cin>>n;
dfs(1);
cout<<tot;
return 0;
}
记录,不知道为啥会read 0
by 绿豆沙 @ 2023-07-19 22:06:00
三年前集训时做的,现在退役了还是没看出来哪错了
by Max6700 @ 2023-07-19 22:18:48
@绿豆沙 大致框架没问题啊……我再看看
by Max6700 @ 2023-07-19 22:21:16
@绿豆沙 我这题打表过的
有正解,但……我瞅瞅在机构做的代码
by wangyuzhou @ 2023-07-19 22:46:32
@绿豆沙
vis[2][maxn];
vis[2][cur-i+n]=1;
vis[2][cur-i+n]=0
显然
by wangyuzhou @ 2023-07-19 22:47:36
数组越界会出现除AC外的其他错误
by Z_X_D_ @ 2023-07-20 07:39:50
我去