UVa 10254 - The Priest Mathematician (4柱汉诺塔)
来源:互联网 发布:软件漏洞扫描工具 编辑:程序博客网 时间:2024/04/28 22:33
4柱汉诺塔问题(大数运算处理)
递推公式:f(1)=1, f(i)=min(2f(k)+2^(i-k)-1 ,1<=k<i)
得到数列:1,3,5,9,13,17,25,33,41,49,65...
规律:f(1)=1,之后每i个数增加2^(i-1),i为大于等于2的自然数列,用大数处理即可
附代码:
#include <stdio.h>#include <string.h>int d2[120][60];int hanoi[10050][60];int main(){ int n; memset(d2,0,sizeof(d2)); d2[0][0]=1; for(int i=1; i<=150; i++) { for(int j=0; j<60; j++) { d2[i][j]+=d2[i-1][j]*2; if(d2[i][j]>9) { d2[i][j+1]++; d2[i][j]%=10; } } } memset(hanoi,0,sizeof(hanoi)); hanoi[0][0]=0; int p=1; for(int i=0; i<=150 && p<=10000; i++) { for(int j=1; j<=i+1 && p<=10000; j++) { for(int k=0; k<60; k++) { hanoi[p][k]+=hanoi[p-1][k]+d2[i][k]; if(hanoi[p][k]>9) { hanoi[p][k+1]++; hanoi[p][k]%=10; } } p++; } } while(scanf("%d",&n)==1) { int s; for(int i=59;i>=0;i--) { if(hanoi[n][i]!=0){s=i;break;} } for(int i=s;i>=0;i--) printf("%d",hanoi[n][i]); printf("\n"); } return 0;}
- UVa 10254 - The Priest Mathematician (4柱汉诺塔)
- uva 10254 the priest mathematician
- uva 10254 - The Priest Mathematician
- UVA 10254 The Priest Mathematician
- UVA 10254 The Priest Mathematician
- uva 10254 The Priest Mathematician
- UVa Problem Solution: 10254 - The Priest Mathematician
- uva 10254 - The Priest Mathematician(dp)
- UVA 10254 - The Priest Mathematician(规律)
- uva 10254——The Priest Mathematician
- UVa Problem 10254 The Priest Mathematician (牧师数学家)
- UVA 10254 - The Priest Mathematician (dp | 汉诺塔 | 找规律 | 大数)
- UVa 10254 The Priest Mathematician (组合数学&规律发现&高精度)
- UVA 10254-The Priest Mathematician(大数+递推)
- The Priest Mathematician
- UVA10254 - The Priest Mathematician(找规律)
- UVA - 1420 Priest John's Busiest Day
- HOJ 2252 The Priest(动态规划)
- android之状态栏提示
- PDP相关
- 儿时的梦想您实现了吗?——《与时间同行》(8)
- grep学习笔记
- amlogic 8726 M6(无显示屏版本)编译
- UVa 10254 - The Priest Mathematician (4柱汉诺塔)
- 解决Failed to add the host to the list of known hosts
- Spring中PropertyPlaceholderConfigurer的使用
- 类 - 2【C++ Primer 学习笔记 - 第十二章】
- Android内存泄漏就这样产生了
- Android 4.1 Netd详细分析(五)代码分析3
- 【HTTP&网络&技术】HTTP中的缓存
- UltraEdit 使用技巧笔记(转) .
- 让你提升命令行效率的 Bash 快捷键 [完整版]