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 ;
}
bjfu1277 简单递归的更多相关文章
- FJ的字符串-简单递归
FJ的字符串-简单递归 问题描述FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = “ABA” A3 = “ABACABA” A4 = “ABACABADABACABA” … … 你能找出其 ...
- java应用简单递归
毕业后就怎么学过算法,还在上学的时候学过数据结构,现在基本上都还给老师了,可惜老师学费没有还给我... 情景: 类似于给定一个数字,算他由多少个数字组成,比如:36 现在有10.5.1 ,那么最佳帅3 ...
- C#(简单递归)和实现IComparable接口
递归: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- 关于简单递归在python3中的实现
话不多说,奉上代码: #倒计时 def count_down(i): if i <= 0: return else: print(str(i)) count_down(i - 1) #求阶乘 d ...
- 公用表表达式CTE简单递归使用-简单树形结构
1.建表脚本 CREATE TABLE [dbo].[tb_tree]( ,) NOT NULL, [ParentId] [int] NULL, ) NULL, CONSTRAINT [PK_tb_t ...
- HDU1016【简单递归.DFS】
题意:一个环,相邻相加是素数. 思路: 直接深搜就好了.. output limit exceed 了好几发... 因为那个while里面的scanf前面的"~" 后来搜了outp ...
- 简单递归____Fibonacci数列
#include <stdio.h> int fun(int x) { ||x==) ; else return fun(x-1)+fun(x-2); } int main() { int ...
- 递归 CTE
公用表表达式 (CTE) 具有一个重要的优点,那就是能够引用其自身,从而创建递归 CTE.递归 CTE 是一个重复执行初始 CTE 以返回数据子集直到获取完整结果集的公用表表达式. 当某个查询引用递归 ...
- 逆转序列的递归/尾递归(+destructuring assignment)实现(JavaScript + ES6)
这里是用 JavaScript 做的逆转序列(数组/字符串)的递归/尾递归实现.另外还尝鲜用了一下 ES6 的destructuring assignment + spread operator 做了 ...
随机推荐
- NVDIMM典型应用及技术发展
1.典型应用之全系统保护 全系统保护采用超级内存作为系统主存.在系统异常掉电时,将整个系统的运行状态(包括CPU,芯片组,其他外设以及所有进程的信息)存入超级内存.在供电恢复后,利用超级内存中的数据, ...
- MyBatis实现SaveOrUpdate
这篇文章主要讲如何通过xml方式实现SaveOrUpdate,但是仍然建议在Service中实现. 例子 <insert id="saveOrUpdate" > < ...
- ajax 一个 gbk 目标后内容乱码的解决方案
ajax 一个 gbk 目标后,如果内容出现乱码,说明服务器在送出内容时没有指定 charset,ajax 对于没有指定 charset 的 response 默认以 utf-8 来处理,所有出现乱码 ...
- 微信jssdk uploadImage 巨坑
//解决IOS无法上传的坑 if (localId.indexOf("wxlocalresource") != -1) { localId = localId.replace(&q ...
- asp.net收藏和设为首页的代码
1:设为首页 <a href="javascript:void(0);" id="setHomePage" onclick="this.styl ...
- php面向对象的三大特征 封装,继承,多态
对象的主要三个特性 对象的行为:可以对 对象施加那些操作,开灯,关灯就是行为. 对象的形态:当施加那些方法是对象如何响应,颜色,尺寸,外型. 对象的表示:对象的表示就相当于身份证,具体区分在相同的行为 ...
- PHP 简介
lamp LAMP - Linux Apache MySQL PHP MySQL - 三个层次:文件层次,服务层次,界面层次. LAMP-Linux Apache MySQL PHP 本机 :127. ...
- Linux之Samba的配置
Samba的配置 对于linux与windows共享,和平共处,我们可以用Samba软件 Samba是一套免费的开源软件,可以在linux或其他类unix操作系统上实现windows域控制器,文件 ...
- shell查找匹配行,输出该行并输出下面的一行
查找匹配行,输出该行并输出下面的一行 grep: grep -A 1 'keyword' file awk:awk '$0~/keyword/{print $0; getline; print $ ...
- 浅谈javascript中的作用域
首先说明一下:Js中的作用域不同于其他语言的作用域,要特别注意 JS中作用域的概念: 表示变量或函数起作用的区域,指代了它们在什么样的上下文中执行,亦即上下文执行环境.Javascript的作 ...