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 做了 ...
随机推荐
- js网页滚动条滚动事件实例分析
本文实例讲述了js网页滚动条滚动事件用法.分享给大家供大家参考.具体分析如下: 在做js返回顶部的效果时,要监听网页滚动条滚动事件,这个事件就是:window.onscroll.当onscroll事件 ...
- 调试EF源代码环境配置
下载EF6的源代码,运行build编译,Nuget会自动下载所需的DLL. 打开EF的工程,可以在EF解决方案下直接新建调试用的项目代码 添加EF引用时选择解决方案中的Entity Framework ...
- Backbone seajs demo2
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- KMP,模式匹配算法
[QQ群: 189191838,对算法和C++感兴趣可以进来] 我们经常会遇到一种情况是匹配两个字符串,看strPar中是否含有str子串,如果有则返回子串在父串strPar中的位置,如果不存在则返回 ...
- 7.cadence原理图后续[原创]
一.网表输出 1.自动编号 输出网表前,不能有问号 -- 效果: ---- -- 效果: 2.DRC检查 输出网表前需要DRC检查 3.网表输出 二.生成BOM表 法1: 法2: --- 点击OK: ...
- 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- ...
- leetcode:Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- core--线程同步(用户模式)
用户模式下的多线程同步只适用用于同一个进程内的多个线程,其范围使用于读写问题:比如一本书,必须是作者A写完之后,读者B才能够读取.否则作者一边修改,读者一边读,完全乱套. 线程读者B如何能在多线程环境 ...
- 跨平台的神器RAD XE5 来啦!!!! XE5破解
什么叫真正的跨平台,DELPHI经过这么长时间的洗礼,如今走上了夸平台的开发之路.希望RAD加油! 先去下一个XE5 再去下一个破解神器 一个破解BDS.exe的神器 开始吧.为了成功破解,请先将电脑 ...
- ionic2rc版常见的一些坑
1.config.xml里的包名不能有横杠,否则在build android的时候会报错 <widget id="com.ionicframework.name-abc" v ...