Problem UVA12627-Erratic Expansion

Accept: 465  Submit: 2487
Time Limit: 3000 mSec

Problem Description

Input

The first line of input is an integer T (T < 1000) that indicates the number of test cases. Each case contains 3 integers K, A and B. The meanings of these variables are mentioned above. K will be in the range [0,30] and 1 ≤ A ≤ B ≤ 2K.

 Output

For each case, output the case number followed by the total number of red balloons in rows [A,B] after K-th hour.
 

 Sample Input

3
0 1 1
3 1 8
3 3 7
 

 Sample Output

Case 1: 1

Case 2: 27

Case 3: 14

题解:本来想找规律,但是纯粹找规律不太好找,参考了一下lrj的思路,设g(k,i)为k小时后第i行及以下的红气球个数,这样递归方程就很好推了(详见代码),红气球的个数很显然是3^k,还有一个注意的点是,举个例子,k=2,则此时最多4行,如果求第5行及以下的气球数,直接返回0即可。

 #include <bits/stdc++.h>

 using namespace std;
typedef long long LL; const int maxn = ; int k, a, b;
int two_pow[maxn];
LL tri_pow[maxn]; LL g(int k, int i) {
if (i > two_pow[k]) return 0LL;
if (k == ) return 1LL;
if (i > two_pow[k - ]) {
return g(k - , i - two_pow[k - ]);
}
else {
return * g(k - , i) + tri_pow[k - ];
}
} int main()
{
//freopen("input.txt", "r", stdin);
int iCase;
scanf("%d", &iCase);
two_pow[] = ;
tri_pow[] = 1LL;
for (int i = ; i <= ; i++) {
two_pow[i] = two_pow[i - ] * ;
tri_pow[i] = tri_pow[i - ] * ;
} int con = ; while (iCase--) {
scanf("%d%d%d", &k, &a, &b);
printf("Case %d: %lld\n", con++, g(k, a) - g(k, b + ));
} return ;
}

UVA12627-Erratic Expansion(递归)的更多相关文章

  1. 12627 - Erratic Expansion——[递归]

    Piotr found a magical box in heaven. Its magic power is that if you place any red balloon inside it ...

  2. 【数形结合】Erratic Expansion

    [UVa12627]Erratic Expansion 算法入门经典第8章8-12(P245) 题目大意:起初有一个红球,每一次红球会分成三红一蓝,蓝球会分成四蓝(如图顺序),问K时的时候A~B行中有 ...

  3. UVa 12627 (递归 计数 找规律) Erratic Expansion

    直接说几个比较明显的规律吧. k个小时以后,红气球的个数为3k. 单独观察一行: 令f(r, k)为k个小时后第r行红气球的个数. 如果r为奇数,f(r, k) = f((r+1)/2, k-1) * ...

  4. 8-12 Erratic Expansion uva12627

    题意:一开始有一个红气球  每小时后一个红气球会变成三个红气球和一个蓝气球  第k小时 a到b行之间有几个红气球 递归找规律题目 一定要注意涉及指数的时候一定要开long long 数组!!!! #i ...

  5. Uva 12627 Erratic Expansion(递归)

    这道题大体意思是利用一种递归规则生成不同的气球,问在某两行之间有多少个红气球. 我拿到这个题,一开始想的是递归求解,但在如何递归求解的思路上我的方法是错误的.在研读了例题上给出的提示后豁然开朗(顺便吐 ...

  6. uva 12627 - Erratic Expansion(递归求解)

    递归的边界条件写的多了--不是必需写呢么多的.. 不明确可共同探讨~ #include<cstdio> #include<iostream> #include<cmath ...

  7. 【例题 8-12 UVA-12627】Erratic Expansion

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 规律+递归题 f[k][i] k时刻前i行的红气球个数 i<=2^(k-1) f[k][i] = 2*f[k-1][i]; i ...

  8. UVA - 12627 Erratic Expansion(奇怪的气球膨胀)(递归)

    题意:问k小时后,第A~B行一共有多少个红气球. 分析:观察图可发现,k小时后,图中最下面cur行的红气球个数满足下式: (1)当cur <= POW[k - 1]时, dfs(k, cur) ...

  9. UVA 12627 - Erratic Expansion

    一个红球能够分裂为3个红球和一个蓝球. 一个蓝球能够分裂为4个蓝球. 分裂过程下图所看到的: 设当前状态为k1.下一状态为k2. k1的第x行红球个数 * 2 ⇒ k2第2*x行的红球个数. k1的第 ...

  10. UVA - 12627 Erratic Expansion 奇怪的气球膨胀 (分治)

    紫书例题p245 Piotr found a magical box in heaven. Its magic power is that if you place any red balloon i ...

随机推荐

  1. js 1.变量提升 2.条件语句 3.循环语句 4.加号+的使用

    1.变量提升 变量提升是浏览器的一个功能,在运行js 代码执行前,浏览器会给js一个全局作用域叫 window,window 分两个模块,一个叫运营模块,内存模块找到当前作用域下的所有带var和fun ...

  2. Flask 系列之 FlaskForm

    通过使用 FlaskForm ,可以方便快捷的实现表单处理. 说明 操作系统:Windows 10 Python 版本:3.7x 虚拟环境管理器:virtualenv 代码编辑器:VS Code 实验 ...

  3. 4种方法实现Html转码

    <script> var HtmlUtil = { /*1.用浏览器内部转换器实现html转码*/ htmlEncode: function(html) { //1.首先动态创建一个容器标 ...

  4. js 年份左右点击加减

    默认为今年 var date = new Date; $scope.year = date.getFullYear(); //年份减 $scope.yearPrev = function(){ $sc ...

  5. js 对象转数组

    function objToArray(array) { var arr = [] for (var i in array) { arr.push(array[i]); } console.log(a ...

  6. JS apply的巧妙用法以及扩展到Object.defineProperty的使用

    Math.max 实现得到数组中最大的一项 var array = [1,2,3,4,5]; var max = Math.max.apply(null, array); console.log(ma ...

  7. FUNCTIONALITY OF ITEM CATEGORY

    Item Category Purpose This wiki page will breify discuss about functionality of Item Category in SAP ...

  8. .net webapi 后台导出excel 申请付款单实例

    [HttpGet, AllowAnonymous] public void ExportSettlementPrint(string code) { FinSettlementModel settle ...

  9. matlab练习程序(点集配准的SVD法)

    上一篇博客中我们使用了四元数法计算ICP. 本篇我们使用SVD计算ICP. 下面是<视觉slam十四讲>中的计算方法: 计算步骤如下: 我们看到,只要求出了两组点之间的旋转,平移是非常容易 ...

  10. 使用Visual Studio Team Services敏捷规划和项目组合管理(五)——组合管理

    使用Visual Studio Team Services敏捷规划和项目组合管理(五)--组合管理 组合待办事项为产品所有者提供关于几个敏捷特性团队工作的洞察.产品所有者可以将高优先级的目标定义为Ep ...