比较简单的递归问题。对于第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 ;
}

bjfu1277 简单递归的更多相关文章

  1. FJ的字符串-简单递归

    FJ的字符串-简单递归 问题描述FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = “ABA” A3 = “ABACABA” A4 = “ABACABADABACABA” … … 你能找出其 ...

  2. java应用简单递归

    毕业后就怎么学过算法,还在上学的时候学过数据结构,现在基本上都还给老师了,可惜老师学费没有还给我... 情景: 类似于给定一个数字,算他由多少个数字组成,比如:36 现在有10.5.1 ,那么最佳帅3 ...

  3. C#(简单递归)和实现IComparable接口

    递归: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...

  4. 关于简单递归在python3中的实现

    话不多说,奉上代码: #倒计时 def count_down(i): if i <= 0: return else: print(str(i)) count_down(i - 1) #求阶乘 d ...

  5. 公用表表达式CTE简单递归使用-简单树形结构

    1.建表脚本 CREATE TABLE [dbo].[tb_tree]( ,) NOT NULL, [ParentId] [int] NULL, ) NULL, CONSTRAINT [PK_tb_t ...

  6. HDU1016【简单递归.DFS】

    题意:一个环,相邻相加是素数. 思路: 直接深搜就好了.. output limit exceed 了好几发... 因为那个while里面的scanf前面的"~" 后来搜了outp ...

  7. 简单递归____Fibonacci数列

    #include <stdio.h> int fun(int x) { ||x==) ; else return fun(x-1)+fun(x-2); } int main() { int ...

  8. 递归 CTE

    公用表表达式 (CTE) 具有一个重要的优点,那就是能够引用其自身,从而创建递归 CTE.递归 CTE 是一个重复执行初始 CTE 以返回数据子集直到获取完整结果集的公用表表达式. 当某个查询引用递归 ...

  9. 逆转序列的递归/尾递归(+destructuring assignment)实现(JavaScript + ES6)

    这里是用 JavaScript 做的逆转序列(数组/字符串)的递归/尾递归实现.另外还尝鲜用了一下 ES6 的destructuring assignment + spread operator 做了 ...

随机推荐

  1. CSS3伪类选择器

    first-line   设置首行样式 first-letter 设置首字母样式 before  在某元素前插入内容并设置内容样式 after 在某元素后插入内容并设置内容样式 <!DOCTYP ...

  2. asp.net mvc4使用百度ueditor编辑器

    原文  http://www.cnblogs.com/flykai/p/3285307.html    已测试 相当不错 前言 配置.net mvc4项目使用ueditor编辑器,在配置过程中遇见了好 ...

  3. 每天一个小算法(Shell Sort2)

    希尔排序: 伪代码: input: an array a of length n with array elements numbered 0 to n − 1 inc ← round(n/2) wh ...

  4. Android内存管理(2)HUNTING YOUR LEAKS: MEMORY MANAGEMENT IN ANDROID PART 2

    from: http://www.raizlabs.com/dev/2014/04/hunting-your-leaks-memory-management-in-android-part-2-of- ...

  5. datagridview中combobox类型的cell选中一个下拉列表之后,立即生效的事件

    public event EventHandler CurrentCellDirtyStateChanged 当单元格的内容已更改,但更改尚未保存时,该单元格将标记为已修改. 此事件通常会在以下情况下 ...

  6. 配置Tomcat 中文字符集问题

    找到Tomcat安装路径下的conf文件夹下的server.xml配置文件,修改配置Tomcat端口的标签"Connector",添加URIEncoding属性,代码如下: < ...

  7. HTML+CSS+JAVASCRIPT 总结

    1. HTML 1: <!doctype html> 2: <!-- This is a test html for html, css, javascript --> 3: ...

  8. Tuning 01 Overview of Oracle Performance Tuning

    永无止境的调优 service level agreements: 是一个量化的调优的指标. performance 只要满足业务OK就可以了, 没必要调的很多, 因为有得必有失, 一方面调的特别优化 ...

  9. Shadow mapping

    http://www.cnblogs.com/cxrs/archive/2009/10/17/1585038.html 1.什么是Shadow Maping?      Shadow Mapping是 ...

  10. 使用public key来做SSH authentication

    public key authentication(公钥认证)是对通过敲用户名.密码方式登录服务器的一种替代办法.这种方法更加安全更具有适应性,但是更难以配置. 传统的密码认证方式中,你通过证明你你知 ...