/******************************************************************************
File : a.c
Project : 1996 9 電脳クラブ
Language : C
Date : 1996.8.18
*****************************************************************************/*
#include <stdio.h>
#include <stdlib.h>
#define N1 1000000
#define N2 10000000
int max = -1;
int cnt[30];
void multi(int sa[] , int sb[] , int i)
{
sa[3] = sb[3] * 10 + sb[2] / N1;
sa[2] = (sb[2] % N1) * 10 + sb[1] / N1;
sa[1] = (sb[1] % N1) * 10 + sb[0] / N1;
sa[0] = (sb[0] % N1) * 10 + i;
}
int remain(int s[] , int i)
{
int r1 , r2 , r3;
int t;
r3 = s[3] % i;
r2 = (r3 * N2 + s[2]) % i;
r1 = (r2 * N2 + s[1]) % i;
t = r1 * N2 + s[0];
return(t % i);
}
int t1[] = {1,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0};
int t2[] = {1,2,1,2,5,2,1,2,1,10,1,2,1,2,5,2,1,2,1,10,1,2,1,2,5,2,1,2,1,10};
void sub(int s0[] , int t[] , int n)
{
int i;
int s1[4];
cnt[n]++;
if(n > max) {
max = n;
}
for(i = t1[n] ; i < 10 ; i+=t2[n]) {
multi(s1 , s0 , i);
if(remain(s1 , n + 1) != 0) continue;
t[n] = i;
sub(s1 , t , n + 1);
}
}
int main(int argc , char **argv)
{
int t[30];
int i0 , i1;
int s0[4] , s1[4];
for(i0 = 1 ; i0 < 30 ; i0++) cnt[i0] = 0;
for(i0 = 1 ; i0 < 10 ; i0++) {
s0[0] = i0;
s0[1] = s0[2] = s0[3] = 0;
t[0] = i0;
sub(s0 , t , 1);
}
for(i0 = 1 ; i0 <= max ; i0++) printf("%2d桁 %4d\n" , i0 , cnt[i0]);
return(0);
}
/******************************************************************************
File : a.c
Project : 1996 8 電脳クラブ
Language : C
Date : 1996.7.18
*****************************************************************************/*
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int x;
int y;
} XY;
int cnt = 0;
XY aa[9];
static XY tt[] = {0,0,1,0,2,0,3,0,4,0,1,1,2,1,3,1,4,1,2,2,3,2,4,2,3,3,4,3,4,4};
void oku(int bb[9][9] , int x , int y , int *d)
{
int xx , yy;
for(yy = 0 ; yy < 9 ; yy++) {
bb[yy][x]++;
if(bb[yy][x] == 1) (*d)++;
}
for(xx = 0 ; xx < 9 ; xx++) {
if(x != xx) {
bb[y][xx]++;
if(bb[y][xx] == 1) (*d)++;
}
}
if(x > 0 && y > 0) {
bb[y - 1][x - 1]++;
if(bb[y - 1][x - 1] == 1) (*d)++;
}
if(x < 8 && y < 8) {
bb[y + 1][x + 1]++;
if(bb[y + 1][x + 1] == 1) (*d)++;
}
if(x < 8 && y > 0) {
bb[y - 1][x + 1]++;
if(bb[y - 1][x + 1] == 1) (*d)++;
}
if(x > 0 && y < 8) {
bb[y + 1][x - 1]++;
if(bb[y + 1][x - 1] == 1) (*d)++;
}
}
void toru(int bb[9][9] , int x , int y)
{
int xx , yy;
for(yy = 0 ; yy < 9 ; yy++) {
bb[yy][x]--;
}
for(xx = 0 ; xx < 9 ; xx++) {
if(x != xx) {
bb[y][xx]--;
}
}
if(x > 0 && y > 0) bb[y - 1][x - 1]--;
if(x < 8 && y < 8) bb[y + 1][x + 1]--;
if(x < 8 && y > 0) bb[y - 1][x + 1]--;
if(x > 0 && y < 8) bb[y + 1][x - 1]--;
}
int cmp(void *a , void *b)
{
if (((XY *)a)->y < ((XY *)b)->y) return(-1);
else if(((XY *)a)->y > ((XY *)b)->y) return(1);
else if(((XY *)a)->x < ((XY *)b)->x) return(-1);
else return(1);
}
void check(int max)
{
XY ww[9];
static XY b1[35][9];
int i , j , k;
for(i = 0 ; i < cnt ; i++) {
for(j = 0 ; j < 7 ; j++) {
for(k = 0 ; k < max ; k++) {
if (j == 0) {
ww[k].x = 8 - aa[k].x;
ww[k].y = aa[k].y;
}
else if(j == 1) {
ww[k].x = aa[k].x;
ww[k].y = 8 - aa[k].y;
}
else if(j == 2) {
ww[k].x = 8 - aa[k].x;
ww[k].y = 8 - aa[k].y;
}
else if(j == 3) {
ww[k].x = aa[k].y;
ww[k].y = aa[k].x;
}
else if(j == 4) {
ww[k].x = 8 - aa[k].y;
ww[k].y = aa[k].x;
}
else if(j == 5) {
ww[k].x = aa[k].y;
ww[k].y = 8 - aa[k].x;
}
else if(j == 6) {
ww[k].x = 8 - aa[k].y;
ww[k].y = 8 - aa[k].x;
}
}
qsort((char *)ww , max , sizeof(XY) , cmp);
for(k = 0 ; k < max ; k++) {
if(b1[i][k].x != ww[k].x) break;
if(b1[i][k].y != ww[k].y) break;
}
if(k == max) return;
}
}
for(j = 0 ; j < max ; j++) {
b1[cnt][j].x = aa[j].x;
b1[cnt][j].y = aa[j].y;
}
qsort((char *)b1[cnt] , max , sizeof(XY) , cmp);
cnt++;
}
void sub2(int bb[9][9] , int x , int y , int c0 , int n , int max)
{
int c1;
int n1;
n1 = n + 1;
x++;
if(x == 9) {
x = 0;
y++;
}
while(y < 9) {
aa[n].x = x;
aa[n].y = y;
c1 = c0;
oku(bb , x , y , &c1);
if(c1 == 81) {
check(max);
}
if(n1 < max) sub2(bb , x , y , c1 , n1 , max);
toru(bb , x , y);
x++;
if(x == 9) {
x = 0;
y++;
}
}
}
void main2(int max)
{
int i;
int x;
int y;
int c;
int bb[9][9];
for(y = 0 ; y < 9 ; y++) {
for(x = 0 ; x < 9 ; x++) {
bb[y][x] = 0;
}
}
for(i = 0 ; i < 15 ; i++) {
aa[0].x = x = tt[i].x;
aa[0].y = y = tt[i].y;
c = 0;
oku(bb , x , y , &c);
sub2(bb , x , y , c , 1 , max);
toru(bb , x , y);
if(x == 9) {
x = 0;
y++;
}
}
printf("%d通り\n" , cnt);
exit(0);
}
void sub1(int bb[9][9] , int x , int y , int c0 , int n , int max)
{
int c1;
n++;
x++;
if(x == 9) {
x = 0;
y++;
}
while(y < 9) {
c1 = c0;
oku(bb , x , y , &c1);
if(c1 == 81) {
printf("%d個\n" , max);
main2(max);
}
if(n < max) sub1(bb , x , y , c1 , n , max);
toru(bb , x , y);
x++;
if(x == 9) {
x = 0;
y++;
}
}
}
void main1(void)
{
int i;
int x;
int y;
int c;
int bb[9][9];
int max;
for(max = 5 ; max < 10 ; max++) {
for(y = 0 ; y < 9 ; y++) {
for(x = 0 ; x < 9 ; x++) {
bb[y][x] = 0;
}
}
for(i = 0 ; i < 15 ; i++) {
x = tt[i].x;
y = tt[i].y;
c = 0;
oku(bb , x , y , &c);
sub1(bb , x , y , c , 1 , max);
toru(bb , x , y);
if(x == 9) {
x = 0;
y++;
}
}
}
}
int main(int argc , char **argv)
{
main1();
return(0);
}
|
第65回(8月)24手
|
|
/******************************************************************************
File : a.c
Project : 1996 5 電脳クラブ
Language : C
Date : 1996.4.18
*****************************************************************************/*
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int t[7][7][7][7];
int ia , ib , ic , id;
t[6][6][6][6] = 1;
for(ia = 6 ; ia >= 0 ; ia--) {
for(ib = 6 ; ib >= 0 ; ib--) {
if(ib > ia) continue;
for(ic = 6 ; ic >= 0 ; ic--) {
if(ic > ib) continue;
for(id = 6 ; id >= 0 ; id--) {
if(id > ic) continue;
if(ia == 6 && ib == 6 && ic == 6 && id == 6) t[ia][ib][ic][id] = 1;
else t[ia][ib][ic][id] = 0;
if(id < 6 && id < ic) t[ia][ib][ic][id] += t[ia][ib][ic][id + 1];
if(ic < 6 && ic < ib) t[ia][ib][ic][id] += t[ia][ib][ic + 1][id];
if(ib < 6 && ib < ia) t[ia][ib][ic][id] += t[ia][ib + 1][ic][id];
if(ia < 6) t[ia][ib][ic][id] += t[ia + 1][ib][ic][id];
}
}
}
}
printf("%d\n" , t[0][0][0][0]);
}
|
第64回(7月)1996
|
|
/******************************************************************************
File : a.c
Project : 1996 4 電脳クラブ
Language : C
Date : 1996.3.18
*****************************************************************************/*
#include <stdio.h>
#include <stdlib.h>
#define NN 42
static int t1[] = { 1, 2, 5, 6, 8, 9,
11,12,15,16,18,19,
21,22,25,26,28,29,
51,52,55,56,58,59,
61,62,65,66,68,69,
81,82,85,86,88,89,
91,92,95,96,98,99};
static int t2[] = { 1, 2, 5, 9, 8, 6,
11,21,51,91,81,61,
12,22,52,92,82,62,
15,25,55,95,85,65,
19,29,59,99,89,69,
18,28,58,98,88,68,
16,26,56,96,86,66};
/* A * B + C + D + E /*
void sub1(void)
{
int i0 , i1 , i2 , i3 , i4;
int s1 , s2 , s3 , s4;
for(i0 = 0 ; i0 < NN ; i0++) {
for(i1 = i0 ; i1 < NN ; i1++) {
s1 = t1[i0] * t1[i1];
if(s1 < 1699) continue;
if(s1 > 1993) continue;
for(i2 = 0 ; i2 < NN ; i2++) {
s2 = s1 + t1[i2];
if(s2 < 1798) continue;
if(s2 > 1994) continue;
for(i3 = i2 ; i3 < NN ; i3++) {
s3 = s2 + t1[i3];
if(s3 < 1897) continue;
if(s3 > 1995) continue;
for(i4 = i3 ; i4 < NN ; i4++) {
s4 = s3 + t1[i4];
if(s4 != 1996) continue;
s4 = t2[i0] * t2[i1] + t2[i2] + t2[i3] + t2[i4];
if(s4 != 9661) continue;
printf("%2d * %2d + %2d + %2d + %2d = 1996 " ,
t1[i0] , t1[i1] , t1[i2] , t1[i3] , t1[i4]);
printf("9661 = %2d+%2d+%2d+%2d*%2d\n" ,
t2[i4] , t2[i3] , t2[i2] , t2[i1] , t2[i0]);
}
}
}
}
}
}
/* A * B * C + D + E /*
void sub2(void)
{
int i0 , i1 , i2 , i3 , i4;
int s1 , s2 , s3 , s4;
for(i0 = 0 ; i0 < NN ; i0++) {
for(i1 = i0 ; i1 < NN ; i1++) {
s1 = t1[i0] * t1[i1];
if(s1 < 1798) continue;
if(s1 > 1994) continue;
for(i2 = i1 ; i2 < NN ; i2++) {
s2 = s1 * t1[i2];
if(s2 < 1798) continue;
if(s2 > 1994) continue;
for(i3 = 0 ; i3 < NN ; i3++) {
s3 = s2 + t1[i3];
if(s3 < 1897) continue;
if(s3 > 1995) continue;
for(i4 = i3 ; i4 < NN ; i4++) {
s4 = s3 + t1[i4];
if(s4 != 1996) continue;
s4 = t2[i0] * t2[i1] * t2[i2] + t2[i3] + t2[i4];
if(s4 != 9661) continue;
printf("%2d * %2d * %2d + %2d + %2d = 1996 " ,
t1[i0] , t1[i1] , t1[i2] , t1[i3] , t1[i4]);
printf("9661 = %2d + %2d + %2d * %2d * %2d\n" ,
t2[i4] , t2[i3] , t2[i2] , t2[i1] , t2[i0]);
}
}
}
}
}
}
/* A * B + C * D + E /*
void sub3(void)
{
int i0 , i1 , i2 , i3 , i4;
int s1 , s2 , s3 , s4;
for(i0 = 0 ; i0 < NN ; i0++) {
for(i1 = i0 ; i1 < NN ; i1++) {
s1 = t1[i0] * t1[i1];
if(s1 > 1996) continue;
for(i2 = i0 ; i2 < NN ; i2++) {
for(i3 = i2 ; i3 < NN ; i3++) {
s3 = s1 + t1[i2] * t1[i3];
if(s3 > 1996) continue;
for(i4 = 0 ; i4 < NN ; i4++) {
s4 = s3 + t1[i4];
if(s4 != 1996) continue;
s4 = t2[i0] * t2[i1] + t2[i2] * t2[i3] + t2[i4];
if(s4 != 9661) continue;
printf("%2d * %2d + %2d * %2d + %2d = 1996 " ,
t1[i0] , t1[i1] , t1[i2] , t1[i3] , t1[i4]);
printf("9661 = %2d + %2d * %2d + %2d * %2d\n" ,
t2[i4] , t2[i3] , t2[i2] , t2[i1] , t2[i0]);
}
}
}
}
}
}
/* A * B * C + D * E /*
void sub4(void)
{
int i0 , i1 , i2 , i3 , i4;
int s1 , s2 , s3 , s4;
for(i0 = 0 ; i0 < NN ; i0++) {
for(i1 = i0 ; i1 < NN ; i1++) {
s1 = t1[i0] * t1[i1];
if(s1 > 1996) continue;
for(i2 = i1 ; i2 < NN ; i2++) {
s2 = s1 * t1[i2];
if(s2 > 1996) continue;
for(i3 = 0 ; i3 < NN ; i3++) {
for(i4 = i3 ; i4 < NN ; i4++) {
s4 = s2 + t1[i3] * t1[i4];
if(s4 != 1996) continue;
s4 = t2[i0] * t2[i1] * t2[i2] + t2[i3] * t2[i4];
if(s4 != 9661) continue;
printf("%2d * %2d * %2d + %2d * %2d = 1996 " ,
t1[i0] , t1[i1] , t1[i2] , t1[i3] , t1[i4]);
printf("9661 = %2d * %2d + %2d * %2d * %2d\n" ,
t2[i4] , t2[i3] , t2[i2] , t2[i1] , t2[i0]);
}
}
}
}
}
}
/* A * B * C * D + E /*
void sub5(void)
{
int i0 , i1 , i2 , i3 , i4;
int s1 , s2 , s3 , s4;
for(i0 = 0 ; i0 < NN ; i0++) {
for(i1 = i0 ; i1 < NN ; i1++) {
s1 = t1[i0] * t1[i1];
if(s1 > 1996) continue;
for(i2 = i1 ; i2 < NN ; i2++) {
s2 = s1 * t1[i2];
if(s2 > 1996) continue;
for(i3 = i2 ; i3 < NN ; i3++) {
s3 = s2 * t1[i3];
if(s3 > 1996) continue;
for(i4 = 0 ; i4 < NN ; i4++) {
s4 = s3 + t1[i4];
if(s4 != 1996) continue;
s4 = t2[i0] * t2[i1] * t2[i2] * t2[i3] + t2[i4];
if(s4 != 9661) continue;
printf("%2d * %2d * %2d * %2d + %2d = 1996 " ,
t1[i0] , t1[i1] , t1[i2] , t1[i3] , t1[i4]);
printf("9661 = %2d + %2d * %2d * %2d * %2d\n" ,
t2[i4] , t2[i3] , t2[i2] , t2[i1] , t2[i0]);
}
}
}
}
}
}
int main(void)
{
sub1();
sub2();
sub3();
sub4();
sub5();
return(0);
}
|
第63回(6月)一本の紐
|
|
/******************************************************************************
File : a.c
Project : 1996 3 電脳クラブ
Language : C
Date : 1996.2.18
*****************************************************************************/*
#include <stdio.h>
#include <stdlib.h>
#define ON 1
#define OFF 0
int b1[4][4][4];
int b2[64][3];
static int dx[] = { 1, 0, 0,-1, 0, 0};
static int dy[] = { 0, 1, 0, 0,-1, 0};
static int dz[] = { 0, 0, 1, 0, 0,-1};
int cnt[65];
int GetCount(int n)
{
int t1 , t2 , t3 , t4;
static int tbl[] = {0 , 1 , 1 , 0};
t1 = tbl[b2[0][0]] + tbl[b2[0][1]] + tbl[b2[0][2]];
t2 = tbl[b2[1][0]] + tbl[b2[1][1]] + tbl[b2[1][2]];
t3 = tbl[b2[n - 1][0]] + tbl[b2[n - 1][1]] + tbl[b2[n - 1][2]];
t4 = tbl[b2[n][0]] + tbl[b2[n][1]] + tbl[b2[n][2]];
if(t1 > t4) return(0);
else if(t1 == t4) {
if(t2 > t3) return(0);
else return(1);
}
else return(1);
}
/* (x1,y1,z1)から(x2,y2,z2)へ行けるか?(0.行けない 1.行ける) /*
int check1(int x1 , int y1 , int z1 , int x2 , int y2 , int z2)
{
int i;
int x3 , y3 , z3;
for(i = 0 ; i < 6 ; i++) {
x3 = x2 + dx[i];
if(x3 < 0 || x3 > 3) continue;
y3 = y2 + dy[i];
if(y3 < 0 || y3 > 3) continue;
z3 = z2 + dz[i];
if(z3 < 0 || z3 > 3) continue;
if(x1 == x3 && y1 == y3 && z1 == z3) continue;
if(b1[x3][y3][z3] == ON) return(0);
}
return(1);
}
/* 始点から延ばせるか?(0.延ばせる 1.延ばせない) /*
int check2()
{
int x2 , y2 , z2;
int i;
for(i = 0 ; i < 6 ; i++) {
x2 = b2[0][0] + dx[i];
if(x2 < 0 || x2 > 3) continue;
y2 = b2[0][1] + dy[i];
if(y2 < 0 || y2 > 3) continue;
z2 = b2[0][2] + dz[i];
if(z2 < 0 || z2 > 3) continue;
if(b1[x2][y2][z2] == ON) continue;
if(check1(b2[0][0] , b2[0][1] , b2[0][2] , x2 , y2 , z2) == 1)
return(0);
}
return(1);
}
void sub(int x1 , int y1 , int z1 , int n)
{
int i;
int x2 , y2 , z2;
int sw = OFF;
b1[x1][y1][z1] = ON;
b2[n][0] = x1;
b2[n][1] = y1;
b2[n][2] = z1;
for(i = 0 ; i < 6 ; i++) {
x2 = x1 + dx[i];
if(x2 < 0 || x2 > 3) continue;
y2 = y1 + dy[i];
if(y2 < 0 || y2 > 3) continue;
z2 = z1 + dz[i];
if(z2 < 0 || z2 > 3) continue;
if(b1[x2][y2][z2] == ON) continue;
if(check1(x1 , y1 , z1 , x2 , y2 , z2) == 0) continue;
sub(x2 , y2 , z2 , n + 1);
sw = ON;
}
if(sw == OFF && check2() == 1) {
cnt[n + 1] += GetCount(n);
}
b1[x1][y1][z1] = OFF;
}
void start(int x1 , int y1 , int z1 , int x2 , int y2 , int z2)
{
b1[x1][y1][z1] = ON;
b2[0][0] = x1;
b2[0][1] = y1;
b2[0][2] = z1;
sub(x2 , y2 , z2 , 1);
b1[x1][y1][z1] = OFF;
}
int main(void)
{
int x , y , z;
int sum = 0;
for(z = 0 ; z < 4 ; z++) {
for(y = 0 ; y < 4 ; y++) {
for(z = 0 ; z < 4 ; z++) {
b1[x][y][z] = OFF;
}
}
}
for(x = 0 ; x < 65 ; x++) cnt[x]= 0;
start(0,0,0 , 1,0,0);
start(1,0,0 , 0,0,0);
start(1,0,0 , 2,0,0);
start(1,0,0 , 1,1,0);
start(1,1,0 , 1,0,0);
start(1,1,0 , 2,1,0);
start(1,1,0 , 1,1,1);
start(1,1,1 , 1,1,0);
start(1,1,1 , 2,1,1);
for(x = 0 ; x < 65 ; x++) {
sum += cnt[x];
if(cnt[x] > 0) printf("%2d マス %10d パターン\n" , x , cnt[x]);
}
printf("計 %10d パターン\n" , sum);
return(0);
}
|
第62回(5月)クラム・ゲーム
|
|
/******************************************************************************
File : a.c
Project : 1996 2 電脳クラブ
Language : C
Date : 1996.1.18
*****************************************************************************/*
#include <stdio.h>
#include <stdlib.h>
#define NN 25
int nn1;
int bb[NN];
int sente(void)
{
int i;
int sts = 0;
for(i = 0 ; i < nn1 ; i++) {
if(bb[i] == 1 || bb[i + 1] == 1) continue;
bb[i] = bb[i + 1] = 1;
sts = gote();
bb[i] = bb[i + 1] = 0;
if(sts == 1) return(1);
}
return(0);
}
int gote(void)
{
int i;
int sts = 1;
for(i = 0 ; i < nn1 ; i++) {
if(bb[i] == 1 || bb[i + 1] == 1) continue;
bb[i] = bb[i + 1] = 1;
sts = sente();
bb[i] = bb[i + 1] = 0;
if(sts == 0) return(0);
}
return(1);
}
int main(void)
{
int i;
int sts = 0;
nn1 = NN - 1;
for(i = 0 ; i < NN / 2 ; i++) bb[i] = 0;
sts = sente();
if(sts == 1) printf("sente\n");
else printf("gote\n");
return(0);
}
|
第60回(3月)Fペントミノ
|
|
/******************************************************************************
File : a.c
Project : 1995 12 電脳クラブ
Language : C
Date : 1995.11.18
*****************************************************************************/*
#include <stdio.h>
static int hx[8][4] = {
-1,0, 1,0 , -1,-1,0,1 , 1,0,-1,0 , 1,1,0,-1 ,
1,0,-1,0 , -1,-1,0,1 , -1,0, 1,0 , 1,1,0,-1};
static int hy[8][4] = {
-1,-1,0,1 , 1,0,-1,0 , 1,1,0,-1 , -1,0, 1,0 ,
-1,-1,0,1 , -1,0, 1,0 , 1,1,0,-1 , 1,0,-1,0};
static int hh[8][8] = {
5,1,3,7,0,6,4,2, 4,2,0,6,1,5,7,3, 7,3,1,5,2,4,6,0, 6,0,2,4,3,7,5,1,
1,5,7,3,4,2,0,6, 0,6,4,2,5,1,3,7, 3,7,5,1,6,0,2,4, 2,4,6,0,7,3,1,5};
static int total = 0;
void disp(int a1[] , int a2[])
{
int bb[8][8];
int x , y;
int i , j;
int b00 , b01 , b10 , b11;
for(y = 0 ; y < 8 ; y++) {
for(x = 0 ; x < 8 ; x++) {
bb[y][x] = -1;
}
}
for(i = 0 ; i < 11 ; i++) {
x = a1[i] % 6 + 1;
y = a1[i] / 6 + 1;
bb[y][x] = i;
for(j = 0 ; j < 4 ; j++) bb[y + hy[a2[i]][j]][x + hx[a2[i]][j]] = i;
}
printf("┌");
for(x = 0 ; x < 8 ; x++) {
printf("─");
if(x < 7) {
if(bb[0][x] == bb[0][x + 1]) printf("─");
else printf("┬");
}
}
printf("┐\n");
for(y = 0 ; y < 8 ; y++) {
printf("│");
for(x = 0 ; x < 8 ; x++) {
printf(" ");
if(x < 7) {
if(bb[y][x] == bb[y][x + 1]) printf(" ");
else printf("│");
}
}
printf("│\n");
if(y < 7) {
if(bb[y][0] == bb[y + 1][0]) printf("│");
else printf("├");
for(x = 0 ; x < 8 ; x++) {
if(bb[y][x] == bb[y + 1][x]) printf(" ");
else printf("─");
if(x < 7) {
b00 = bb[y ][x ];
b01 = bb[y ][x + 1];
b10 = bb[y + 1][x ];
b11 = bb[y + 1][x + 1];
if (b00 == b10 && b01 == b11) printf("│");
else if(b00 == b01 && b10 == b11) printf("─");
else if(b00 == b01 && b00 == b10) printf("┌");
else if(b00 == b01 && b00 == b11) printf("┐");
else if(b00 == b10 && b00 == b11) printf("└");
else if(b01 == b11 && b11 == b10) printf("┘");
else if(b00 == b01 && b10 != b11) printf("┬");
else if(b00 != b10 && b01 == b11) printf("┤");
else if(b00 == b10 && b01 != b11) printf("├");
else if(b00 != b01 && b10 == b11) printf("┴");
else printf("┼");
}
}
if(bb[y][7] == bb[y + 1][7]) printf("│\n");
else printf("┤\n");
}
}
printf("└");
for(x = 0 ; x < 8 ; x++) {
printf("─");
if(x < 7) {
if(bb[7][x] == bb[7][x + 1]) printf("─");
else printf("┴");
}
}
printf("┘\n");
}
void check(int a1[] , int a2[])
{
static int d1[8][11] , d2[8][11];
int b1[6][6];
int x , y;
int i , j , k;
int sw;
for(y = 0 ; y < 6 ; y++) {
for(x = 0 ; x < 6 ; x++) b1[y][x] = -1;
}
for(j = 0 ; j < 11 ; j++) {
b1[a1[j] % 6][a1[j] / 6] = a2[j];
}
for(i = 0 ; i < total ; i++) {
for(j = 0 ; j < 8 ; j++) {
sw = 0;
for(k = 0 ; k < 11 ; k++) {
x = d1[i][k] % 6;
y = d1[i][k] / 6;
if (j == 0 && b1[y ][x ] == hh[d2[i][k]][j]) sw = 1;
else if(j == 1 && b1[5 - y][x ] == hh[d2[i][k]][j]) sw = 1;
else if(j == 2 && b1[y ][5 - x] == hh[d2[i][k]][j]) sw = 1;
else if(j == 3 && b1[5 - y][5 - x] == hh[d2[i][k]][j]) sw = 1;
else if(j == 4 && b1[x ][y ] == hh[d2[i][k]][j]) sw = 1;
else if(j == 5 && b1[5 - x][y ] == hh[d2[i][k]][j]) sw = 1;
else if(j == 6 && b1[x ][5 - y] == hh[d2[i][k]][j]) sw = 1;
else if(j == 7 && b1[5 - x][5 - y] == hh[d2[i][k]][j]) sw = 1;
}
if(sw == 0) return;
}
}
for(k = 0 ; k < 11 ; k++) {
d1[total][k] = a1[k];
d2[total][k] = a2[k];
}
disp(a1 , a2);
total++;
}
void sub1(int a1[] , int a2[] , int bb[][8] , int n)
{
int i , h , x , y;
int s = 0;
if(n > 0) s = a1[n - 1];
x = s % 6;
y = s / 6 + 1;
for(i = s ; i < 26 + n ; i++) {
x++;
if(x == 7) {
x = 1;
y++;
}
if(bb[y][x] == -1) {
for(h = 0 ; h < 8 ; h++) {
if(bb[y + hy[h][0]][x + hx[h][0]] != -1) continue;
if(bb[y + hy[h][1]][x + hx[h][1]] != -1) continue;
if(bb[y + hy[h][2]][x + hx[h][2]] != -1) continue;
if(bb[y + hy[h][3]][x + hx[h][3]] != -1) continue;
bb[y][x] = n;
bb[y + hy[h][0]][x + hx[h][0]] = n;
bb[y + hy[h][1]][x + hx[h][1]] = n;
bb[y + hy[h][2]][x + hx[h][2]] = n;
bb[y + hy[h][3]][x + hx[h][3]] = n;
a1[n] = i;
a2[n] = h;
if(n < 10) sub1(a1 , a2 , bb , n + 1);
else check(a1 , a2);
bb[y][x] = -1;
bb[y + hy[h][0]][x + hx[h][0]] = -1;
bb[y + hy[h][1]][x + hx[h][1]] = -1;
bb[y + hy[h][2]][x + hx[h][2]] = -1;
bb[y + hy[h][3]][x + hx[h][3]] = -1;
}
}
}
}
int main(void)
{
int a1[11] , a2[11];
int bb[8][8];
int x , y;
for(y = 0 ; y < 8 ; y++) {
for(x = 0 ; x < 8 ; x++) bb[y][x] = -1;
}
sub1(a1 , a2 , bb , 0);
printf("解答 = %d 通り\n" , total);
return(0);
}
|
第59回(2月)お散歩仲間
|
|
/******************************************************************************
File : a.c
Project : 1995 11 電脳クラブ
Language : C
Date : 1995.10.18
*****************************************************************************/*
#include <stdio.h>
#define ON 1
#define OFF 0
int a1[15][15];
int b1[7][15];
void disp(void)
{
int x , y;
for(y = 0 ; y < 7 ; y++) {
printf("%d日目 : " , y + 1);
for(x = 0 ; x < 15 ; x += 3) {
printf("(%2d %2d %2d)" , b1[y][x] , b1[y][x + 1] , b1[y][x + 2]);
}
printf("\n");
}
exit(0);
}
void sub(int n)
{
int i00 = 0 , i01 , i02;
int i10 = 1 , i11 , i12;
int i20 = 2 , i21 , i22;
int i30 , i31 , i32;
int i40 , i41 , i42;
int c1[15];
int j;
for(j = 0 ; j < 15 ; j++) c1[j] = OFF;
c1[0] = c1[1] = c1[2] = ON;
b1[n][0] = i00;
b1[n][3] = i10;
b1[n][6] = i20;
for(i01 = 3 ; i01 < 15 ; i01++) {
if(c1[i01] == ON) continue;
if(a1[i00][i01] == ON) continue;
b1[n][1] = i01;
c1[i01] = ON;
a1[i00][i01] = ON;
for(i02 = i01 + 1 ; i02 < 15 ; i02++) {
if(c1[i02] == ON) continue;
if(a1[i00][i02] == ON) continue;
if(a1[i01][i02] == ON) continue;
b1[n][2] = i02;
c1[i02] = ON;
a1[i00][i02] = ON;
a1[i01][i02] = ON;
for(i11 = 3 ; i11 < 14 ; i11++) {
if(c1[i11] == ON) continue;
if(a1[i10][i11] == ON) continue;
b1[n][4] = i11;
c1[i11] = ON;
a1[i10][i11] = ON;
for(i12 = i11 + 1 ; i12 < 15 ; i12++) {
if(c1[i12] == ON) continue;
if(a1[i10][i12] == ON) continue;
if(a1[i11][i12] == ON) continue;
b1[n][5] = i12;
c1[i12] = ON;
a1[i10][i12] = ON;
a1[i11][i12] = ON;
for(i21 = i20 + 1 ; i21 < 14 ; i21++) {
if(c1[i21] == ON) continue;
if(a1[i20][i21] == ON) continue;
b1[n][7] = i21;
c1[i21] = ON;
a1[i20][i21] = ON;
for(i22 = i21 + 1 ; i22 < 15 ; i22++) {
if(c1[i22] == ON) continue;
if(a1[i20][i22] == ON) continue;
if(a1[i21][i22] == ON) continue;
b1[n][8] = i22;
c1[i22] = ON;
a1[i20][i22] = ON;
a1[i21][i22] = ON;
for(i30 = i20 + 1 ; i30 < 13 ; i30++) {
if(c1[i30] == ON) continue;
c1[i30] = ON;
b1[n][9] = i30;
for(i31 = i30 + 1 ; i31 < 14 ; i31++) {
if(c1[i31] == ON) continue;
if(a1[i30][i31] == ON) continue;
b1[n][10] = i31;
c1[i31] = ON;
a1[i30][i31] = ON;
for(i32 = i31 + 1 ; i32 < 15 ; i32++) {
if(c1[i32] == ON) continue;
if(a1[i30][i32] == ON) continue;
if(a1[i31][i32] == ON) continue;
b1[n][11] = i32;
c1[i32] = ON;
a1[i30][i32] = ON;
a1[i31][i32] = ON;
for(i40 = i30 + 1 ; i40 < 13 ; i40++) {
if(c1[i40] == ON) continue;
b1[n][12] = i40;
c1[i40] = ON;
for(i41 = i40 + 1 ; i41 < 14 ; i41++) {
if(c1[i41] == ON) continue;
if(a1[i40][i41] == ON) continue;
b1[n][13] = i41;
c1[i41] = ON;
a1[i40][i41] = ON;
for(i42 = i41 + 1 ; i42 < 15 ; i42++) {
if(c1[i42] == ON) continue;
if(a1[i40][i42] == ON) continue;
if(a1[i41][i42] == ON) continue;
b1[n][14] = i42;
a1[i40][i42] = ON;
a1[i41][i42] = ON;
if(n == 6) {
disp();
}
else {
sub(n + 1);
}
a1[i40][i42] = OFF;
a1[i41][i42] = OFF;
}
a1[i40][i41] = OFF;
c1[i41] = OFF;
}
c1[i40] = OFF;
}
a1[i30][i32] = OFF;
a1[i31][i32] = OFF;
c1[i32] = OFF;
}
a1[i30][i31] = OFF;
c1[i31] = OFF;
}
c1[i30] = OFF;
}
a1[i20][i22] = OFF;
a1[i21][i22] = OFF;
c1[i22] = OFF;
}
a1[i20][i21] = OFF;
c1[i21] = OFF;
}
a1[i10][i12] = OFF;
a1[i11][i12] = OFF;
c1[i12] = OFF;
}
a1[i10][i11] = OFF;
c1[i11] = OFF;
}
a1[i00][i02] = OFF;
a1[i01][i02] = OFF;
c1[i02] = OFF;
}
a1[i00][i01] = OFF;
c1[i01] = OFF;
}
}
int main(void)
{
int i , j;
for(i = 0 ; i < 15 ; i++) {
b1[0][i] = i;
for(j = 0 ; j < 15 ; j++) {
a1[i][j] = OFF;
}
}
a1[0][1] = a1[0][2] = a1[1][2] = ON;
a1[3][4] = a1[3][5] = a1[4][5] = ON;
a1[6][7] = a1[6][8] = a1[6][8] = ON;
a1[9][10] = a1[9][11] = a1[10][11] = ON;
a1[12][13] = a1[12][14] = a1[13][14] = ON;
sub(1);
return(0);
}
|
第58回(1月)6×6=36
|
|
/******************************************************************************
File : puzzle1.c (高速版)
Project : 1995 10 電脳クラブ
Language : C
Date : 1995.09.18
*****************************************************************************/*
#include <stdio.h>
#define ON 1
#define OFF 0
int main(void)
{
int i0 , i1 , i2 , i3 , i4 , i5;
int j0 , j1 , j2 , j3 , j4 , j5;
int ff[38];
int k;
for(k = 2 ; k < 38 ; k++) ff[k] = OFF;
i0 = 1;
j0 = 1;
ff[i0 + j0] = ON;
i1 = 2;
ff[i1 + j0] = ON;
for(j1 = j0 + 2 ; j1 < 33 ; j1++) {
if(i0 + j1 > 37) continue;;
if(ff[i0 + j1] == ON) continue;;
if(i1 + j1 > 37) continue;;
if(ff[i1 + j1] == ON) continue;;
ff[i0 + j1] = ON;
ff[i1 + j1] = ON;
for(i2 = i1 + 1 ; i2 < 34 ; i2++) {
if(i2 + j0 > 37) continue;
if(ff[i2 + j0] == ON) continue;
if(i2 + j1 > 37) continue;
if(ff[i2 + j1] == ON) continue;
ff[i2 + j0] = ON;
ff[i2 + j1] = ON;
for(j2 = j1 + 2 ; j2 < 34 ; j2++) {
if(i0 + j2 > 37) continue;
if(ff[i0 + j2] == ON) continue;
if(i1 + j2 > 37) continue;
if(ff[i1 + j2] == ON) continue;
if(i2 + j2 > 37) continue;
if(ff[i2 + j2] == ON) continue;
ff[i0 + j2] = ON;
ff[i1 + j2] = ON;
ff[i2 + j2] = ON;
for(i3 = i2 + 1 ; i3 < 35 ; i3++) {
if(i3 + j0 > 37) continue;
if(ff[i3 + j0] == ON) continue;
if(i3 + j1 > 37) continue;
if(ff[i3 + j1] == ON) continue;
if(i3 + j2 > 37) continue;
if(ff[i3 + j2] == ON) continue;
ff[i3 + j0] = ON;
ff[i3 + j1] = ON;
ff[i3 + j2] = ON;
for(j3 = j2 + 2 ; j3 < 35 ; j3++) {
if(i0 + j3 > 37) continue;
if(ff[i0 + j3] == ON) continue;
if(i1 + j3 > 37) continue;
if(ff[i1 + j3] == ON) continue;
if(i2 + j3 > 37) continue;
if(ff[i2 + j3] == ON) continue;
if(i3 + j3 > 37) continue;
if(ff[i3 + j3] == ON) continue;
ff[i0 + j3] = ON;
ff[i1 + j3] = ON;
ff[i2 + j3] = ON;
ff[i3 + j3] = ON;
for(i4 = i3 + 1 ; i4 < 36 ; i4++) {
if(i4 + j0 > 37) continue;
if(ff[i4 + j0] == ON) continue;
if(i4 + j1 > 37) continue;
if(ff[i4 + j1] == ON) continue;
if(i4 + j2 > 37) continue;
if(ff[i4 + j2] == ON) continue;
if(i4 + j3 > 37) continue;
if(ff[i4 + j3] == ON) continue;
ff[i4 + j0] = ON;
ff[i4 + j1] = ON;
ff[i4 + j2] = ON;
ff[i4 + j3] = ON;
for(j4 = j3 + 2 ; j4 < 36 ; j4++) {
if(i0 + j4 > 37) continue;
if(ff[i0 + j4] == ON) continue;
if(i1 + j4 > 37) continue;
if(ff[i1 + j4] == ON) continue;
if(i2 + j4 > 37) continue;
if(ff[i2 + j4] == ON) continue;
if(i3 + j4 > 37) continue;
if(ff[i3 + j4] == ON) continue;
if(i4 + j4 > 37) continue;
if(ff[i4 + j4] == ON) continue;
ff[i0 + j4] = ON;
ff[i1 + j4] = ON;
ff[i2 + j4] = ON;
ff[i3 + j4] = ON;
ff[i4 + j4] = ON;
for(i5 = i4 + 1 ; i5 < 37 ; i5++) {
if(i5 + j0 > 37) continue;
if(ff[i5 + j0] == ON) continue;
if(i5 + j1 > 37) continue;
if(ff[i5 + j1] == ON) continue;
if(i5 + j2 > 37) continue;
if(ff[i5 + j2] == ON) continue;
if(i5 + j3 > 37) continue;
if(ff[i5 + j3] == ON) continue;
if(i5 + j4 > 37) continue;
if(ff[i5 + j4] == ON) continue;
ff[i5 + j0] = ON;
ff[i5 + j1] = ON;
ff[i5 + j2] = ON;
ff[i5 + j3] = ON;
ff[i5 + j4] = ON;
j5 = 37 - i5;
if (ff[i0 + j5] == ON) ;
else if(ff[i1 + j5] == ON) ;
else if(ff[i2 + j5] == ON) ;
else if(ff[i3 + j5] == ON) ;
else if(ff[i4 + j5] == ON) ;
else if(ff[i5 + j5] == ON) ;
else {
printf("(%2d %2d %2d %2d %2d %2d)",i0,i1,i2,i3,i4,i5);
printf("(%2d %2d %2d %2d %2d %2d)\n",j0,j1,j2,j3,j4,j5);
}
ff[i5 + j0] = OFF;
ff[i5 + j1] = OFF;
ff[i5 + j2] = OFF;
ff[i5 + j3] = OFF;
ff[i5 + j4] = OFF;
}
ff[i0 + j4] = OFF;
ff[i1 + j4] = OFF;
ff[i2 + j4] = OFF;
ff[i3 + j4] = OFF;
ff[i4 + j4] = OFF;
}
ff[i4 + j0] = OFF;
ff[i4 + j1] = OFF;
ff[i4 + j2] = OFF;
ff[i4 + j3] = OFF;
}
ff[i0 + j3] = OFF;
ff[i1 + j3] = OFF;
ff[i2 + j3] = OFF;
ff[i3 + j3] = OFF;
}
ff[i3 + j0] = OFF;
ff[i3 + j1] = OFF;
ff[i3 + j2] = OFF;
}
ff[i0 + j2] = OFF;
ff[i1 + j2] = OFF;
ff[i2 + j2] = OFF;
}
ff[i2 + j0] = OFF;
ff[i2 + j1] = OFF;
}
ff[i0 + j1] = OFF;
ff[i1 + j1] = OFF;
}
return(0);
}
/******************************************************************************
File : puzzle2.c (再帰版)
Project : 1995 10 電脳クラブ
Language : C
Date : 1995.09.18
*****************************************************************************/*
#include <stdio.h>
#define ON 1
#define OFF 0
void subi5(int gri[] , int grj[] , int ff[])
{
int k;
grj[5] = 37 - gri[5];
if(grj[5] < grj[4]) return;
for(k = 0 ; k < 6 ; k++) {
if(ff[gri[k] + grj[5]] == ON) return;
}
printf("(%2d %2d %2d %2d %2d %2d) (%2d %2d %2d %2d %2d %2d)\n",
gri[0],gri[1],gri[2],gri[3],gri[4],gri[5],
grj[0],grj[1],grj[2],grj[3],grj[4],grj[5]);
}
void subii(int gri[] , int grj[] , int ff[] , int m , int dd)
{
int i , k;
for(k = 0 ; k < m + dd ; k++) {
if(gri[m] + grj[k] > 37) return;
if(ff[gri[m] + grj[k]] == ON) return;
}
for(k = 0 ; k < m + dd ; k++) ff[gri[m] + grj[k]] = ON;
if (dd == 0 && m == 5) subi5(gri , grj , ff);
else if(dd == 0) {
for(i = grj[m - 1] + 1 ; i < 37 ; i++) {
grj[m] = i;
subii(grj , gri , ff , m , 1);
}
}
else {
for(i = gri[m] + 1 ; i < 37 ; i++) {
gri[m + 1] = i;
subii(gri , grj , ff , m + 1 , 0);
}
}
for(k = 0 ; k < m + dd ; k++) ff[gri[m] + grj[k]] = OFF;
}
int main(void)
{
int j , k;
int ff[38];
int gri[6] , grj[6];
gri[0] = 1;
grj[0] = 1;
gri[1] = 2;
for(k = 2 ; k < 38 ; k++) ff[k] = OFF;
ff[gri[0] + grj[0]] = ON;
ff[gri[1] + grj[0]] = ON;
for(j = grj[0] + 1 ; j < 34 ; j++) {
grj[1] = j;
subii(grj , gri , ff , 1 , 1);
}
return(0);
}
| | | | | | | |