for depth 1, the left-right cycle is two balls
for depth 2, the cycle is 4 balls
...
for depth k, the cycle is 1<<k balls
and the branch condition, i%2?goleft:goright won't change forever
/* UVas */
/*****************************************************************************/
int n, D, I;
int main(void) {
cin>>n;
while(n--) {
cin>>D>>I;
int k=1;
for (int i=1; i<D; i++) {
if (I%2) {
I=(I+1)/2;
k*=2;
} else {
I/=2;
k=k*2+1;
}
}
cout<<k<<endl;
}
return 0;
}
/*****************************************************************************/
No comments :
Post a Comment