3 #define MAX 12 // actually, it's 1 more than max
4 #define NST (MAX*MAX*MAX)
6 int status[NST], queue[NST], back[NST], qr, qw;
7 int capa[3], goal[MAX], gback[MAX];
9 #define ENCODE(i,j,k) ((i)*MAX*MAX+(j)*MAX+(k))
10 #define DECODE(i,j,k,x) (i)=(x)/(MAX*MAX), (j)=(x)/MAX%MAX, (k)=(x)%MAX
12 static void go(int x, int *t)
14 // printf("\t-> %d %d %d\n", t[0], t[1], t[2]);
15 int y = ENCODE(t[0], t[1], t[2]);
18 status[y] = status[x] + 1;
24 static void search(void)
26 for (int i=1; i<NST; i++)
28 for (int i=0; i<MAX; i++)
38 DECODE(t[0],t[1],t[2],x);
39 // printf("%5d %d,%d,%d (%d)\n", x, t[0], t[1], t[2], status[x]);
40 for (int i=0; i<3; i++)
43 goal[t[i]] = status[x];
46 for (int i=0; i<3; i++)
55 for (int i=0; i<3; i++)
56 for (int j=0; j<3; j++)
59 int r = capa[j] - t[j];
72 for (int f=0; f<NST; f++)
74 DECODE(capa[0], capa[1], capa[2], f);
75 if (!capa[0] || !capa[1] || !capa[2]
76 || (capa[0] == capa[1] || capa[0] == capa[2] || capa[1] == capa[2]) && 1
77 || !(capa[0] <= capa[1] && capa[1] <= capa[2])
80 printf("%d,%d,%d: ", capa[0], capa[1], capa[2]);
83 for (int i=0; i<MAX; i++)
84 if (goal[i] > goal[best])
87 for (int i=0; i<NST; i++)
90 printf("%2d (%d) r=%d\n", goal[best], best, reach);
102 printf("%d,%d,%d\n", a,b,c);