相关代码 |
|
#include "stdio.h" #include "math.h" #include "stdlib.h" void queen(int n) { int i,j,k,jt,*q; q=malloc(n*sizeof(int)); for(i=0; i i=0; jt=1; printf("\n"); printf("%d queen problem\n",n); while(jt==1) { if (q[i] { k=0; while((k (fabs(q[k]-q[i])-fabs(k-i)))!=0) k=k+1; if (k else { if (i==n-1) { for(j=0; j printf("%5d",q[j]+1); printf("\n"); q[n-1]=q[n-1]+1; } else i=i+1; } } else { q[i]=0; i=i-1; if (i { printf("\n"); free(q); return; } q[i]=q[i]+1; } } }
相关资源 |
|