sizhenhualei @ 2024-07-17 10:27:34
#include<bits/stdc++.h>
using namespace std;
bool b[300],d[300],c[300];
int sum=0,a[300],x;
int search(int);
void print();
void print()
{
int i;
sum++;
if(sum<=3){
for (i=1;i<=x;i++)
cout<<a[i]<<" ";
cout<<endl;
}
}
int search(int i){
int j;
for (j=1;j<=x;j++)//i行j个
if((!b[j])&&(!c[i+j])&&(!d[i-j+30])){
a[i]=j;
b[j]=1;
c[i+j]=1;
d[i-j+30]=1;
if(i==x) print();
else search(i+1);
b[j]=0;
c[i+j]=0;
d[i-j+30]=0;
}
}
int main(){
cin>>x;
search(1);
cout<<sum;
return 0;
}
by Im_Joker @ 2024-07-17 10:30:37
#include<bits/stdc++.h>
using namespace std;
bool b[300],d[300],c[300];
int sum=0,a[300],x;
void print()
{
int i;
sum++;
if(sum<=3){
for (i=1;i<=x;i++)
cout<<a[i]<<" ";
cout<<endl;
}
}
void search(int i){
int j;
for (j=1;j<=x;j++)//i行j个
if((!b[j])&&(!c[i+j])&&(!d[i-j+30])){
a[i]=j;
b[j]=1;
c[i+j]=1;
d[i-j+30]=1;
if(i==x) print();
else search(i+1);
b[j]=0;
c[i+j]=0;
d[i-j+30]=0;
}
}
int main(){
cin>>x;
search(1);
cout<<sum;
return 0;
}
by Zivsfamily @ 2024-07-18 17:59:05
关于int类型函数没有返回值这件事