HDU 4260 The End of The World(汉罗塔)
来源:互联网 发布:阿里云服务器能转让吗 编辑:程序博客网 时间:2024/06/10 06:37
/*汉罗塔问题,要用到一个公式:假设N个盘子都在A上,那么搬到B上则需要2^N - 1次。dfs(B, pos)的作用是:将前面pos个盘子全部搬到B上所需要多少次。这样,dfs(B, pos) = dfs(C, pos - 1) + pow(2.0, pos - 1) - 1 + 1;即,先将pos - 1个盘子都放在C处,然后将最后剩余一个盘子放在B上,再将C上面的盘子都放回B处。dfs中的B\C具体需要转换*/#include <cstdio>#include <cstring>#include <cmath>const int nMax = 65;char s[nMax];__int64 dfs(char B, int pos){if(pos == 0){if(s[0] == B) return 0;else return 1;}else{if(s[pos] == B) return dfs(B, pos - 1);else{return (__int64)pow(2.0, pos) + dfs(3*'B' - B - s[pos], pos - 1);}}}int main(){while(gets(s)){if(s[0] == 'X') break;int len = strlen(s);__int64 ans = dfs('B', len - 1);printf("%I64d\n", ans);}return 0;}
- HDU 4260 The End of The World(汉罗塔)
- HDU 4260 The End of The World(汉罗塔)
- HDU 4260 The End of The World
- hdu 4260 The End of The World
- hdu 4260 汉诺塔问题 The End of The World
- Hdu 4596 Yet another end of the world(数论)
- HDU 4596Yet another end of the world(GCD)
- HDU-4596 Yet another end of the world (数论)
- HDU 4260 The End of The World (递推&递归) #by Plato
- HDU 4260(The End of The World-Hanoi塔从中间状态移动)
- hdu 4596 Yet another end of the world(数论)
- HDU 4596 Yet another end of the world
- [欧几里得] hdu 4596 Yet another end of the world
- HDU OJ 4596 Yet another end of the world
- HDU 4569——Yet another end of the world
- HDU 4596 Yet another end of the world (拓展欧几里得)
- HDU4260 The End of The World
- HDU 4596 (Yet another end of the world)(二进制进位次数和)
- Android JSON字符串解析和构建
- C语言复制字符串
- sizeof(struct var) 的长度如何计算
- 写宏定义:得到一个field在结构体(struct type)中的偏移量[转]
- 头文件包含
- HDU 4260 The End of The World(汉罗塔)
- java split
- android视频项目使用资源
- 带眼镜的一定要看!一个眼镜批发商的话
- Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask等【转】
- 为Linux MySQL数据库设置磁盘限额
- Hibernate 继承映射(二)
- 聚合(Aggregation)和组合(Composition)区别
- CCNP收官