UVA12627 Erratic Expansion
来源:互联网 发布:js登录清除cookie 编辑:程序博客网 时间:2024/06/08 16:12
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4352
解题思路:
找规律题。然后用递归求解。
AC代码:
#include<iostream>#include<cstdio>#include<cmath>using namespace std;typedef long long ll;ll num[35],l[35];int n;ll fun(int k,int x){ if(x==0) return 0; if(x==l[k]) return num[k]; else { if(x>l[k-1]) return fun(k-1,x%l[k-1])+2*num[k-1]; else return 2*fun(k-1,x); }}int main(){ int i,j; num[0]=1;l[0]=1; for(i=1;i<=30;i++) { num[i]=3*num[i-1]; l[i]=2*l[i-1]; } int T,tt=1; scanf("%d",&T); while(T--) { int a,b; scanf("%d%d%d",&n,&a,&b); printf("Case %d: %lld\n",tt++,fun(n,b)-fun(n,a-1)); } return 0;}
0 0
- UVA12627 Erratic Expansion
- uva12627 erratic expansion
- UVA12627 Erratic Expansion
- uva12627 Erratic Expansion
- uva12627 Erratic Expansion (递归)
- UVA12627 Erratic Expansion (递归找规律)
- UVA12627:Erratic Expansion(奇怪的气球膨胀)
- Uva12627 Erratic Expansion【分治】【例题8-12】
- uva12627 - Erratic Expansion 入门经典II 第八章 例题8-12
- 算法竞赛入门经典 例题8-12 奇怪的气球膨胀 Erratic Expansion uva12627
- 例题8-12 奇怪的气球膨胀(Erratic Expansion, UVa12627)
- Uva Erratic Expansion
- 12627 - Erratic Expansion
- uva 12627 erratic expansion
- UVa 12627 - Erratic Expansion
- UVa 12627 Erratic Expansion
- Uva - 12627 - Erratic Expansion
- UVA 12627 - Erratic Expansion
- POJ1298 The Hardest Problem Ever
- Flume+kafka+storm整合
- systemctl替代service与chkconfig
- HDU1028 Ignatius and the Princess III(母函数模板)
- POJ 2328 解题报告
- UVA12627 Erratic Expansion
- IT小李传--药店里的装饰模式
- Apache Hadoop 2.6.0 新特性
- 第12 章 索引
- Qt QLineEdit QLabel添加clicked事件,给控件添加事件方法
- 数学之路-数据分析进阶-Cox比例风险回归模型
- 新的一周
- [LeetCode] Remove Duplicates from Sorted Linked List 从排序链表中去掉重复值
- Java中由substring方法引发的内存泄漏