uva750-8 Queens Chess Problem请问我这样写为什么不行?
#include<stdio.h>#include <stdlib.h>
#define N 15
int n;
int max;
int x[N], num[95][10];
int place(int k)
{
int i;
for(i=1; i<k; i++)
if(abs(k-i)==abs(x[k]-x[i]) || x[k] == x[i])
return 0;
return 1;
}
void queen(int cur)
{
int i, sum = 1;
if(cur>8 && cur>0)
sum++;
else
for(i=1; i<=8; i++)
{
x[cur] = i;
if(place(cur))
{
num[sum][cur] = x[cur];
cur++;
queen(cur);
}
}
}
int main()
{
int n, p, q;
int i, j;
while(scanf("%d",&n)==1)
{
queen(1);
while(n--)
{
scanf("%d%d", &p, &q);
printf("SOLN COLUMN\n");
printf(" # 1 2 3 4 5 6 7 8\n\n");
int count = 1;
for (i = 1; i <= count ; i++)
if(num[i][q] == p)
{
printf("%2d ", count++);
for (j = 1; j <= 8 ; j++)
printf(" %d",num[i][j]);
printf("\n");
}
if(n) printf("\n");
}
}
return 0;
}
[此贴子已经被作者于2017-3-25 12:55编辑过]