小球下路(刘书)

感觉是类似分治的思想,每一次向下都是第奇数个小球往左走,第偶数个小球往右走。然后接着往下向左走的小球有I=(I+1)/2;向右走的小球有I=I/2。那么直到要走d-1次,输出k。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <string>
 4 #include <map>
 5 #include <set>
 6 #include <algorithm>
 7 #include <fstream>
 8 #include <cstdio>
 9 #include <cmath>
10 #include <stack>
11 #include <queue>
12 #include <deque> 
13 using namespace std;
14 const double Pi=3.14159265358979323846;
15 typedef long long ll;
16 const int MAXN=(1<<20)+5;
17 const int dx[5]={0,0,0,1,-1};
18 const int dy[5]={1,-1,0,0,0};
19 const int INF = 0x3f3f3f3f;
20 const int NINF = 0xc0c0c0c0;
21 const ll mod=1e9+7;
22 bool s[MAXN];
23 int main()
24 {
25     int D;int I;
26     int t;cin>>t;int k;
27     while(t--)
28     {    
29         scanf("%d%d",&D,&I);
30         int n=(1<<D)-1;
31         k=1;
32         for(int i=1;i<=D-1;i++)
33         {
34             if(I%2) k=k*2;
35                 else k=k*2+1;
36             I=(I+1)/2;
37         }
38         cout << k <<endl;
39     }
40     return 0;
41 }

 

转载于:https://www.cnblogs.com/Msmw/p/10617836.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值