Chloe and the sequence CodeForces - 743B
考察:推导(?)
思路:
k所表示的数一定可以在某一层的2n-1的位置上.对于当前n,如果k>2n-1,那么将它调到左边k-=2n-1,如果<说明k所代表数在下一层,=即可跳出.
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 typedef long long LL; 5 LL n,k; 6 int solve() 7 { 8 int s = n,cnt = 0; 9 LL res = 1ll<<s-1; 10 while(k!=res) 11 { 12 if(k<res) s--; 13 else k-=res; 14 res = 1ll<<(s-1); 15 } 16 while(k) 17 { 18 k/=2; 19 cnt++; 20 } 21 return cnt; 22 } 23 int main() 24 { 25 scanf("%lld%lld",&n,&k); 26 int ans = solve(); 27 printf("%d\n",ans); 28 return 0; 29 }