JZOJ 2136. 【GDKOI2004】汉诺塔
JZOJ 2136. 【GDKOI2004】汉诺塔
2136. 【GDKOI2004】汉诺塔 (Standard IO)
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <algorithm> 5 using namespace std; 6 int t; 7 long long n, m; 8 9 int main() 10 { 11 scanf("%d", &t); 12 int g[6] = {1, 2, 3, 3, 2, 1}; 13 while (t--) 14 { 15 scanf("%lld%lld", &n, &m); 16 long long p = 6, p2 = 1; 17 for (int i = 1; i <= n - 1; i++) 18 { 19 printf("%d ", g[(m % p) / p2]); 20 p *= 3; 21 p2 *= 3; 22 } 23 printf("%d", g[(m % p) / p2]); 24 if (t != 0) printf("\n"); 25 } 26 }