【HDOJ】1207 汉诺塔II
这道题目单纯用找规律解得,自己求了很多值,发现规律。相邻dx的数,会相差2^n,需要求对dx。
#include <stdio.h> int main() { int tower[65] = {0}; int i, j=1, k=1, shift=0, n; for (i=1; i<65; ++i) { if (i>k) { j++; k = (j+1)*j/2; shift++; } tower[i] = tower[i-1] + (1<<shift); } while (scanf("%d", &n) != EOF) printf("%d\n", tower[n]); return 0; }