比赛 暑假培训二 评测结果 AAAAAAAAAA
题目名称 跳棋的挑战 最终得分 100
用户昵称 BYVoid 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2008-07-18 10:50:02
显示代码纯文本
#include <stdio.h>
FILE *fi,*fo;
unsigned long int upperlim,sum;
int a[15],n;

int ps(int a)
{
	switch (a)
	{
	case 1:
		return 1;
	case 2:
		return 2;
	case 4:
		return 3;
	case 8:
		return 4;
	case 16:
		return 5;
	case 32:
		return 6;
	case 64:
		return 7;
	case 128:
		return 8;
	case 256:
		return 9;
	case 512:
		return 10;
	case 1024:
		return 11;
	case 2048:
		return 12;
	case 4096:
		return 13;
	case 8192:
		return 14;
	}
}

void test(unsigned long int row,unsigned long int ld,unsigned long int rd,int deep)
{
	unsigned long int pos,p;
	if (row!=upperlim)
	{
     pos=upperlim & ~(row | ld | rd);
     while (pos!=0) 
     {
        p=pos & -pos;
        pos=pos-p;
		if (sum<3) a[deep]=p;
        test(row+p,(ld+p)<< 1,(rd+p)>> 1,deep+1);
	 }
	}
 else
{
	sum++;
	int i;
	if (sum<=3) 
	{
		for (i=1;i<=n-1;i++)
			fprintf(fo,"%d ",ps(a[i]));
		fprintf(fo,"%d\n",ps(a[n]));
	}
}

}

int main(void)
{
	fi=fopen("checker.in","r");
	fo=fopen("checker.out","w");
	fscanf(fi,"%d",&n);
	fclose(fi);
	upperlim=(1 << n)-1;
	test(0,0,0,1);
	fprintf(fo,"%d\n",sum);
	fclose(fo);
	return 0;
}