YONEX @ 2024-04-30 20:17:59
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[15000];
int b[20000];
int c[20000];
int d[20000];
int ans[1000];
int cnt=0;
int k;
int nudge=0;
void prt()
{
int j;
cnt++;
for(j=1;j<=k;j++)
{
cout<<ans[j]<<" ";
}
cout<<endl;
}
void count()
{
int j;
for(j=1;j<=k;j++)
{
nudge++;
}
}
int search(int i)
{
int j;
for(j=1;j<=k;j++)
{
if(a[j]==0 and c[i-j+9]==0 and d[i+j]==0)
{
ans[i]=j;
a[j]=1;
c[i-j+9]=1;
d[i+j]=1;
if(i==k and cnt<3)
{
prt();
}
if(i==k)
{
count();
}
else
search(i+1);
a[j]=0;
c[i-j+9]=0;
d[i+j]=0;
}
}
}
int main()
{
cin>>k;
search(1);
cout<<nudge/k;
return 0;
}
by _int123_ @ 2024-04-30 20:49:05
@love_nn search 函数没返回值
by _int123_ @ 2024-04-30 20:50:51
@love_nn ac代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[15000];
int b[20000];
int c[20000];
int d[20000];
int ans[1000];
int cnt=0;
int k;
int nudge=0;
void prt()
{
int j;
cnt++;
for(j=1;j<=k;j++)
{
cout<<ans[j]<<" ";
}
cout<<endl;
}
void count()
{
int j;
for(j=1;j<=k;j++)
{
nudge++;
}
}
void search(int i)
{
int j;
for(j=1;j<=k;j++)
{
if(a[j]==0 and c[i-j+9]==0 and d[i+j]==0)
{
ans[i]=j;
a[j]=1;
c[i-j+9]=1;
d[i+j]=1;
if(i==k and cnt<3)
{
prt();
}
if(i==k)
{
count();
}
else
search(i+1);
a[j]=0;
c[i-j+9]=0;
d[i+j]=0;
}
}
}
int main()
{
cin>>k;
search(1);
cout<<nudge/k;
return 0;
}
by YONEX @ 2024-05-07 21:02:11
@int123 拜谢,一关