一个红球能够分裂为3个红球和一个蓝球。

一个蓝球能够分裂为4个蓝球。

分裂过程下图所看到的:

设当前状态为k1。下一状态为k2

k1的第x行红球个数 * 2 ⇒ k2第2*x行的红球个数。

k1的第x行红球个数 ⇒ k2第2*x+1行的红球个数。

特殊处理一下上下边界。递归求解就能够搞定了。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <assert.h>
#include <time.h>
#include <sstream> typedef long long LL;
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
long long gao(int k, int a, int b)
{
if(a > b) return 0;
if(k == 0)
{
return 1;
}
int left = 0, right = 0;
if(a % 2 == 0)
{
left = a;
a++;
}
if(b % 2 == 1)
{
right = b;
b--;
}
long long ans = gao(k-1, (a + 1) / 2, b / 2) * 2 + gao(k - 1, (a + 1) / 2, b / 2);
if(left) ans += gao(k-1, left / 2, left / 2);
if(right) ans += gao(k-1, (right + 1) / 2, (right + 1) / 2) * 2;
return ans;
}
int main()
{
#ifdef _Te3st
freopen("test0.in", "r", stdin);
freopen("test0.out", "w", stdout);
srand(time(NULL));
#endif
int T, k, a, b;
scanf("%d", &T);
for(int i = 1; i <= T; i++)
{
scanf("%d %d %d", &k, &a, &b);
printf("Case %d: %lld\n", i, gao(k, a, b));
}
return 0;
}

UVA 12627 - Erratic Expansion的更多相关文章

  1. UVa 12627 Erratic Expansion - 分治

    因为不好复制题目,就出给出链接吧: Vjudge传送门[here] UVa传送门[here] 请仔细看原题上的那幅图,你会发现,在时间t(t > 0),当前的气球构成的一幅图,它是由三个时间为( ...

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

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

  3. Uva 12627 Erratic Expansion(递归)

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

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

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

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

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

  6. UVA 12673 Erratic Expansion 奇怪的气球膨胀 (递推)

    不难发现,每过一个小时,除了右下方的气球全都是蓝色以外,其他都和上一个小时的气球是一样的,所以是可以递推的.然后定义一类似个前缀和的东西f(k,i)表示k小时之后上面i行的红气球数.预处理出k小时的红 ...

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

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

  8. 【数形结合】Erratic Expansion

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

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

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

随机推荐

  1. 1003. Parity(并查集)

    1003 看篇国家论文 <从<parity>的解法谈程序优化> 对于区间i,j 如果用sum[i],sum[j]来表示到i的1的个数的奇偶性 那么仔细想下 sum[i-1] 若 ...

  2. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  3. bzoj1453

    这是一道好题,按行建线段树,每个点维护上下边界的连通性,详细见代码注释 网上写法不一,自认为比较简单,就放出来相出来献丑吧 ..,..] of longint; //u[]上边界,d[]下边界 s,f ...

  4. unity3d游戏物体跟着鼠标方向移动

    效果:当点击鼠标左键时,游戏对象会朝鼠标点击的方向移动,类似魔兽争霸一样. 思路:把鼠标的坐标转化成世界坐标(鼠标默认是屏幕坐标),然后当点击鼠标时,物体将朝着鼠标的世界坐标方向移动. 如果你看到这的 ...

  5. fingerprintjs

    Valve/fingerprintjs FingerprintJS - 在浏览器端实现指纹识别

  6. CentOS6.5_Nginx1.40_Php5.57_MySQL5.5.35编译安装全记录

    环境说明:CentOS 6.5 32位  PHP Version 5.5.7  mysql version _5.6.16 一.准备工作 配置防火墙,允许防火墙通过22(sshd).80(WEB).3 ...

  7. Java [leetcode 35]Search Insert Position

    题目描述: Given a sorted array and a target value, return the index if the target is found. If not, retu ...

  8. DataTable 分页

    #region DataTable 分页 /// <summary> /// Datatable 分页 /// </summary> /// <param name=&q ...

  9. List<HashMap>和HashMap

      例如select查询出的是学号.姓名,比如查出符合条件的是学号是0810的小红,学号是0811的小明,组织起来如下:  list.add(hashmap1);list.add(hashmap2); ...

  10. 在 MacOS 上编译链接 OpenGL 程序

    几个星期以前开始折腾在我的MBA上写 OpenGL 小程序.我不太熟悉MacOS上的开发工具比如XCode,所以一开始的想法就是用vim来写程序,然后手工编译链接.网上查了一下,MacOS上的Open ...