The main idea: a sequence, beginning from 0 to 1, and then a change in the future
The rule of change is that if the current number is k, at the end of the sequence, add k-1 0, plus k+1
Now ask what the nth number of this sequence is.
Problem-solving ideas: This is a regular, the 2nd K-square number is just K
If the current number is k, and K is exactly 2 of the N-square, then this number is preceded by a n-1 0,n-2 1,n-3 02 combination, and so on
If the number of nth is required, only need to find the n is which K before, and then according to the law of the above in order to recursively go down
#include <cstdio>#include <cstring>using namespace STD;#define MAXNtypedef unsigned Long LongUll;ull POS[MAXN], NUM[MAXN];voidInit () {num[0] = num[1] =1; for(inti =2; i < MAXN; i++) Num[i] = num[i-1] *2; pos[1] =2; for(inti =2; i < MAXN; i++) Pos[i] = pos[i-1] *2;}intDFS (Ull len,intN) {if(len = =0) {returnN }intnow =0; for(inti = n-1; i >0; i--) {if(Len > I * num[now]) len-= i * num[now];Else{if(now = =0|| now = =1) {returnNow } len = (Len-1)% Num[now];returnDFS (Len, now); } now++; }}intMain () {init ();Long LongN while(scanf("%lld", &n) = =1&& N) {if(n = =1) {printf("0\n");Continue; } for(inti =1; I <= -; i++) {if(n <= pos[i]) {printf("%d\n", DFS (Pos[i]-N, i)); Break; } } }}
UVA 10479 the Hendrie Sequence law