比较简单的递归问题。对于第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. wordpress模块无法拖拽/显示选项点击无反应

    问题:wordpress模块无法拖拽/显示选项点击无反应,还有编辑器的全屏什么的都用不了,按F12查看了console,提示很多jQuery is not defined... 解决方法:把wp-in ...

  2. 转载网页博客:ie7bug:div容器下的img与div存在间隙

    1.代码及在浏览器上的显示 ie7: ie8+: Firefox: Chrome: 可以看出ie7上在div容器下添加img,div与img中有间隙,而在ie8+和其他浏览器上均显示正常 网页源代码如 ...

  3. Intellij编译时报“java: System Java Compiler was not found in classpath” 解决办法

    Intellij编译时报“java: System Java Compiler was not found in classpath” 解决方法: Project Settings > Comp ...

  4. Oracle ->> 查看分区表的每个分区的数据行分布情况

    ora_hash函数用来返回分区号,而dbms_rowid.rowid_object()函数用来返回object_id , ) part_id ,count(*) from sales_fact_pa ...

  5. JQuery获取浏览器窗口的高度和宽度

    <script type="text/javascript"> $(document).ready(function() { alert($(window).heigh ...

  6. C#基础(二)

    变量的命名规则: 1.变量名由字母,数字 ,下划线组成.@ 中文 2.首字母,不能是数字 3.不能与关键字重名 变量的定义 语法: 数据类型 变量名[=值]; int a;      //只定义变量 ...

  7. android下使用smack需引入的包

    compile 'org.igniterealtime.smack:smack-android:4.2.0-alpha1' compile 'org.igniterealtime.smack:smac ...

  8. 石阶 VS 石像

    山庙有尊雕刻精美的佛像,前来拜佛的人络绎不绝. 铺在山路上的石阶开始抱怨:“大家同是石头,凭什么我被人蹬来踩去,你却被人供在殿堂?” 佛像笑了笑:“当年你只挨六刀,做了一方石阶,而我经历了千刀万凿之后 ...

  9. hdu-4893-Wow! Such Sequence!-线段树【2014多校第三场-J】

    题意:一个初始为0的数组,支持三种操作:1.向第k个数添加d,(|d| < 2^31);2.把[l, r]区间内的数字都换成与它最相近的Fibonacci数;3.询问[l, r]区间的和. 思路 ...

  10. ORACLE EBS R12 - 寄售功能知多少

    材料以寄售方式供应,是制造业实现零库存管理的一种方式.东西放在我这里,不用的时候,东西还是供应商的,用的时候,按"装机"数量进行付款.这种业务模式,对于竞争日趋白热化的家电行业,非 ...