bjfu1277 简单递归

比较简单的递归问题。对于第k时刻的图形,可以平均分成四块,左上,右上,左下这三块的图形是一模一样的,右下的那一块不包含红毛僵尸,所以把那三块里的加起来就是结果了。

/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef long long LL;
LL three[]; LL work(int k, int a, int b) {
int side = << (k - );
if (a > side || b < ) {
return ;
}
if (a <= && b >= side) {
return three[k - ];
}
int aa = a - ( << (k - ));
int bb = b - ( << (k - ));
return * work(k - , a, b) + work(k - , aa, bb);
} int main() {
int T, a, b, k;
three[] = ;
for (int i = ; i <= ; i++) {
three[i] = three[i - ] * ;
}
scanf("%d", &T);
for (int t = ; t <= T; t++) {
scanf("%d%d%d", &k, &a, &b);
printf("Case %d: %lld\n", t, work(k, a, b));
}
return ;
}
上一篇:MYSQL之MHA集群


下一篇:使用python做科学计算