#include<stdio.h>
#include<math.h>
#define N 8
int s[N];
int main(void)
{
find(0);
puts("/n");
}
void find(int n)
{
int i;
if (n==8) {
display();
return;
}
for (i = 1; i <= N; i++) {
s[n] = i;
if (isright(n))
find(n+1);
}
}
int isright(int n)
{
int i;
for (i = 0; i < n; i++) {
if((abs(s[n] - s[i]) == abs(n - i)) || (s[i] == s[n]))
return 0;
}
return 1;
}
void display()
{
int i;
for (i = 0; i < N; i++)
printf("%d/t", s[i]);
printf("/n");
}
2万+


&spm=1001.2101.3001.11974&articleId=437963&d=1&t=3&u=e241e077dfc8443a915291a09f802391)

被折叠的 条评论
为什么被折叠?



