/**//*
ID: lorelei3
TASK: checker
LANG: C++
*/
#include <fstream>
FILE *fi, *fo;
const int N = 20;
int n ;
int sum =0;
int a[20];
unsigned long int upperlim ;
int ps(int a) //不用 log 节省时间
{
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;
}
}
void test(unsigned long int row, unsigned long int ld, unsigned long int rd, int depth){
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[depth] = p;
test(row+p, (ld+p)<<1, (rd+p)>>1, depth+1);
}
}else{
sum++;
if(sum<=3){
for (int i=0;i<n-1;i++)
fprintf(fo,"%d ",ps(a[i]));
fprintf(fo,"%d\n",ps(a[n-1]));
}
}
}
int main(void) {
fi = fopen("checker.in", "r");
fo = fopen("checker.out", "w");
fscanf(fi, "%d", &n);
upperlim = (1<<n)-1;
test(0, 0, 0, 0);
fprintf(fo, "%d\n", sum);
return 0;
}
posted on 2010-11-09 13:00
小阮 阅读(167)
评论(0) 编辑 收藏 引用 所属分类:
USACO