博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【例题 8-12 UVA-12627】Erratic Expansion
阅读量:4448 次
发布时间:2019-06-07

本文共 882 字,大约阅读时间需要 2 分钟。

【链接】

【题意】

在这里输入题意

【题解】

规律+递归题
f[k][i] k时刻前i行的红气球个数
i<=2^(k-1)
f[k][i] = 2*f[k-1][i];

i>2^(k-1)        f[k][i] = 2*c[k-1] + f[k-1][i-2^(k-1)];c[k]表示k时刻红气球个数显然k时刻有3^k个红气球

【代码】

#include 
#define ll long longusing namespace std;const int N = 30;int k,a,b;ll two[N+10],three[N+10];ll f(int k,int i){ if (i==0) return 0; if (k==0) return 1; if (i <= (two[k-1])) return 2*f(k-1,i); else return 2*three[k-1] + f(k-1,i-two[k-1]);}int main(){ #ifdef LOCAL_DEFINE freopen("rush_in.txt", "r", stdin); #endif ios::sync_with_stdio(0),cin.tie(0); int T; two[0] = three[0] = 1; for (int i = 1;i <= N;i++) two[i] = two[i-1]*2,three[i] = three[i-1]*3; int kase = 0; cin >> T; while (T--){ cin >> k >> a >> b; cout <<"Case "<<++kase<<": "<< f(k,b) - f(k,a-1)<

转载于:https://www.cnblogs.com/AWCXV/p/8191673.html

你可能感兴趣的文章
用bat 删除当前文件夹下的某类文件
查看>>
先序遍历和后序遍历构建二叉树
查看>>
linux xorddos样本分析1
查看>>
【数论】-素数问题整理
查看>>
提高你的Java代码质量吧:正确使用String、StringBuffer、StringBuilder
查看>>
[happyctf]部分writeup
查看>>
HDU 1195 Open the Lock(BFS)
查看>>
Struts2的crud
查看>>
java上传文件
查看>>
大学生对技术网站需求的调查问卷结果分析
查看>>
测试一
查看>>
vertx的HttpServer模块
查看>>
as3事件流机制彻底理解
查看>>
Selenium webdriver操作日历控件
查看>>
Pascal程序练习-与7无关的数
查看>>
Linux:cut命令...未完待续
查看>>
微信小程序从零开始开发步骤(一)搭建开发环境
查看>>
SQL*Net more data to client
查看>>
Tcpdump使用方法总结
查看>>
PX4地面站QGroundControl在ubuntu下的安装
查看>>