UVA_254
At first, I found the wrong question. I didn't do it according to the requirements of the question. If I do it according to the algorithm described in the question, the result of moving n to an even number is the same as what we normally do, when n is an odd number, all the plates will be moved to the middle column, which is actually equivalent to the intermediate column and the last column.
When looking for the status, we can use recursion. First, we specify the initial column s of the plate heap, and the column t that the Bottom Plate of the heap is expected to move, start from the largest plate, and discuss whether the largest plate can be moved, and then change the corresponding state to continue recursion.
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static int[] a = new int[5];
public static BigInteger[] d = new BigInteger[110];
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n;
BigInteger m;
d[0] = new BigInteger("1");
for(int i = 1; i <= 100; i ++)
d[i] = d[i - 1].multiply(BigInteger.valueOf(2));
while(cin.hasNext())
{
n = cin.nextInt();
m = cin.nextBigInteger();
if(n == 0)
break;
for(int i = 0; i < 3; i ++)
a[i] = 0;
dfs(0, 2, n, m);
if(n % 2 == 0)
System.out.println(a[0] + " " + a[1] + " " + a[2]);
else
System.out.println(a[0] + " " + a[2] + " " + a[1]);
}
}
public static void dfs(int s, int t, int n, BigInteger m)
{
if(n == 1)
{
if(m.equals(BigInteger.ZERO))
a[s] ++;
else
a[t] ++;
return ;
}
int k = 0;
{
int[] x = new int[3];
x[s] = 1;
x[t] = 1;
for(int i = 0; i < 3; i ++)
if(x[i] == 0)
k = i;
}
if(m.compareTo(d[n - 1]) != -1)
{
++ a[t];
m = m.add(d[n - 1].negate());
dfs(k, t, n - 1, m);
}
else
{
++ a[s];
dfs(s, k, n - 1, m);
}
}
}