【链接】 我是链接,点我呀:)
【题意】
【题解】
规律+递归题 f[k][i] k时刻前i行的红气球个数 i<=2^(k-1) f[k][i] = 2*f[k-1][i]; i>2^(k-1)
f[k][i] = 2*c[k-1] + f[k-1][i-2^(k-1)];
c[k]表示k时刻红气球个数
显然k时刻有3^k个红气球
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 30;
int k,a,b;
ll two[N+10],three[N+10];
ll f(int k,int i){
if (i==0) return 0;
if (k==0) return 1;
if (i <= (two[k-1]))
return 2*f(k-1,i);
else
return 2*three[k-1] + f(k-1,i-two[k-1]);
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
two[0] = three[0] = 1;
for (int i = 1;i <= N;i++)
two[i] = two[i-1]*2,three[i] = three[i-1]*3;
int kase = 0;
cin >> T;
while (T--){
cin >> k >> a >> b;
cout <<"Case "<<++kase<<": "<< f(k,b) - f(k,a-1)<<endl;
}
return 0;
}