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
Sample Input
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(递归)的更多相关文章
- 12627 - Erratic Expansion——[递归]
Piotr found a magical box in heaven. Its magic power is that if you place any red balloon inside it ...
- 【数形结合】Erratic Expansion
[UVa12627]Erratic Expansion 算法入门经典第8章8-12(P245) 题目大意:起初有一个红球,每一次红球会分成三红一蓝,蓝球会分成四蓝(如图顺序),问K时的时候A~B行中有 ...
- UVa 12627 (递归 计数 找规律) Erratic Expansion
直接说几个比较明显的规律吧. k个小时以后,红气球的个数为3k. 单独观察一行: 令f(r, k)为k个小时后第r行红气球的个数. 如果r为奇数,f(r, k) = f((r+1)/2, k-1) * ...
- 8-12 Erratic Expansion uva12627
题意:一开始有一个红气球 每小时后一个红气球会变成三个红气球和一个蓝气球 第k小时 a到b行之间有几个红气球 递归找规律题目 一定要注意涉及指数的时候一定要开long long 数组!!!! #i ...
- Uva 12627 Erratic Expansion(递归)
这道题大体意思是利用一种递归规则生成不同的气球,问在某两行之间有多少个红气球. 我拿到这个题,一开始想的是递归求解,但在如何递归求解的思路上我的方法是错误的.在研读了例题上给出的提示后豁然开朗(顺便吐 ...
- uva 12627 - Erratic Expansion(递归求解)
递归的边界条件写的多了--不是必需写呢么多的.. 不明确可共同探讨~ #include<cstdio> #include<iostream> #include<cmath ...
- 【例题 8-12 UVA-12627】Erratic Expansion
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 规律+递归题 f[k][i] k时刻前i行的红气球个数 i<=2^(k-1) f[k][i] = 2*f[k-1][i]; i ...
- UVA - 12627 Erratic Expansion(奇怪的气球膨胀)(递归)
题意:问k小时后,第A~B行一共有多少个红气球. 分析:观察图可发现,k小时后,图中最下面cur行的红气球个数满足下式: (1)当cur <= POW[k - 1]时, dfs(k, cur) ...
- UVA 12627 - Erratic Expansion
一个红球能够分裂为3个红球和一个蓝球. 一个蓝球能够分裂为4个蓝球. 分裂过程下图所看到的: 设当前状态为k1.下一状态为k2. k1的第x行红球个数 * 2 ⇒ k2第2*x行的红球个数. k1的第 ...
- UVA - 12627 Erratic Expansion 奇怪的气球膨胀 (分治)
紫书例题p245 Piotr found a magical box in heaven. Its magic power is that if you place any red balloon i ...
随机推荐
- hive 导出如数为csv格式
hive导出csv格式的数据 命令如下: hive -e "select concat_ws(',',appKey,clickJson) adt.jsontest as st from &q ...
- canvas-8clip.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Linux上Simplescalar/ARM的安装和运行文档
本文是基于ARM的simplescalar在ubuntu下的安装说明 1.1 软件下载 *********************文件下载地址:http://yunpan.cn/cw2n7dAyfG ...
- 小tips:HTML DOM中的children和childNodes属性
childNodes 属性 标准的,childNodes 属性返回节点的子节点集合,以 NodeList 对象.包括HTML节点,所有属性,文本.可以通过nodeType来判断是哪种类型的节点,只有当 ...
- BZOJ4916: 神犇和蒟蒻(杜教筛)
题意 求 $$\sum_{i = 1}^n \mu(i^2)$$ $$\sum_{i = 1}^n \phi(i^2)$$ $n \leqslant 10^9$ Sol zz的我看第一问看了10min ...
- SPOJ1811 LCS - Longest Common Substring(后缀自动机)
A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...
- 信息检索中的TF/IDF概念与算法的解释
https://blog.csdn.net/class_brick/article/details/79135909 概念 TF-IDF(term frequency–inverse document ...
- 我写的Java相关的文章
此文正在更新中... Activiti 升级到Activiti7了. Web service/Soap Java如何调用.net写的asmx服务
- JMeter 报告监听器导入.jtl结果文件报错解决方案
JMeter 报告监听器导入.jtl结果文件报错解决方案 by:授客 QQ:1033553122 1. 问题描述 把jmeter压测时生成的 .jtl结果文件导入监听器报告中,弹出如下错误提示 ...
- Implemented the “Importance Sampling of Reflections from Hair Fibers”
Just the indirect specular pass by importance sampling. With all layers. Manually traced by 3D Ham ...