3 条题解
-
1
#include<bits/stdc++.h> using namespace std; long long a[100],f[100],g[100],h[100],n,s=0; void dfs(int d){ if(d>n){ for(int i=1;i<=n;i++) cout<<setw(5)<<a[i]; s=1; cout<<endl; return; } for(int i=1;i<=n;i++){ if(f[i]==0&&g[i+d]==0&&h[i-d+n]==0){ f[i]=1; g[i+d]=1; h[i-d+n]=1; a[d]=i; dfs(d+1); f[i]=0; g[i+d]=0; h[i-d+n]=0; } } } int main(){ cin>>n; dfs(1); if(s==0) cout<<"no solute!"; return 0; } -
0
```#include<bits/stdc++.h> using namespace std; long long n,a[100],t[100],h[100],g[100]; long long d=0; void dfs(int deep){ if(deep==n+1){ for(int i=1;i<=n;i++) { d=1; cout<<setw(5)<<a[i]; } cout<<endl; return; } for(int i=1;i<=n;i++){ if(t[i]==0&&h[i+deep]==0&&g[i-deep+n]==0){ t[i]=h[i+deep]=g[i-deep+n]=1; a[deep]=i; dfs(deep+1); t[i]=h[i+deep]=g[i-deep+n]=0; } } } int main() { cin>>n; dfs(1); if(d<1) cout<<"no solute!"; return 0; } -
-1
using namespace std; long long n,a[100],t[100],h[100],g[100]; long long d=0; void dfs(int deep){ if(deep==n+1){ for(int i=1;i<=n;i++) { d=1; cout<<setw(5)<<a[i]; } cout<<endl; return; } for(int i=1;i<=n;i++){ if(t[i]==0&&h[i+deep]==0&&g[i-deep+n]==0){ t[i]=h[i+deep]=g[i-deep+n]=1; a[deep]=i; dfs(deep+1); t[i]=h[i+deep]=g[i-deep+n]=0; } } } int main() { cin>>n; dfs(1); if(d<1) cout<<"no solute!"; return 0; }
- 1
信息
- ID
- 44
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- (无)
- 递交数
- 101
- 已通过
- 37
- 上传者