首页 > 其他 > 详细

Chloe and the sequence CodeForces - 743B

时间:2021-04-06 20:17:08      阅读:30      评论:0      收藏:0      [点我收藏+]

原题链接

考察:推导(?)

思路:

        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 }

 

Chloe and the sequence CodeForces - 743B

原文:https://www.cnblogs.com/newblg/p/14622255.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!