Hanoi Towers

Time Limit : 10000/5000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 0 Accepted Submission(s) : 0
Special Judge
Problem Description

The “Hanoi Towers” puzzle consists of three pegs (that we will name A, B, and C) with n disks of different diameters stacked onto the pegs. Initially all disks are stacked onto peg A with the smallest disk at the top and the largest one at the bottom, so that they form a conical shape on peg A.

 
Input

The input file contains two lines. The first line consists of a single
integer number n (1 ≤ n ≤ 30) the number of disks in the puzzle.
The second line contains descriptions of six moves separated by spaces the
strategy that is used to solve the puzzle.

 
Output

Write to the output file the number of moves it takes to solve the puzzle.
This number will not exceed 1018.

 
Sample Input
#1 3
AB BC CA BA CB AC
#2 2
AB BA CA BC CB AC
 
Sample Output
#1 7
#2 5
 
 
貌似是一道纯规律的题,我不会做。。。照着网上的规律敲了一遍,感觉网上的大神真厉害。
 
题意:对于一个汉诺塔,每次按照给定的顺序,找第一个可以移动的方式去移动。要求不能大的下面放小的,且不能连续两次移动同一个盘子。
 
附上代码:
 #include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[],b[],c[];
int num[];
char s[];
int main()
{
int n,i,j,k;
a[]=b[]=c[]=;
for(i=; i<=; i++)
{
a[i]=a[i-]*+;
c[i]=c[i-]*+;
b[i]=b[i-]+c[i-]+;
}
scanf("%d",&n);
for(i=; i<=; i++)
{
scanf("%s",s);
k=(s[]-'A')*+s[]-'A';
num[k]=i;
}
if(num[]<num[])
{
if(num[]<num[])
printf("%I64d\n",c[n]);
else if(num[]<num[])
printf("%I64d\n",b[n]);
else
printf("%I64d\n",a[n]);
}
else
{
if(num[]<num[])
printf("%I64d\n",c[n]);
else if(num[]<num[])
printf("%I64d\n",b[n]);
else
printf("%I64d\n",a[n]);
}
}

poj 3572 Hanoi Tower的更多相关文章

  1. HDU1329 Hanoi Tower Troubles Again!——S.B.S.

    Hanoi Tower Troubles Again! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. ZOJ-1239 Hanoi Tower Troubles Again!

    链接:ZOJ1239 Hanoi Tower Troubles Again! Description People stopped moving discs from peg to peg after ...

  3. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  4. 汉诺塔 Hanoi Tower

    电影<猩球崛起>刚开始的时候,年轻的Caesar在玩一种很有意思的游戏,就是汉诺塔...... 汉诺塔源自一个古老的印度传说:在世界的中心贝拿勒斯的圣庙里,一块黄铜板上插着三支宝石针.印度 ...

  5. HDU 1329 Hanoi Tower Troubles Again!(乱搞)

    Hanoi Tower Troubles Again! Problem Description People stopped moving discs from peg to peg after th ...

  6. 3-6-汉诺塔(Hanoi Tower)问题-栈和队列-第3章-《数据结构》课本源码-严蔚敏吴伟民版

    课本源码部分 第3章  栈和队列 - 汉诺塔(Hanoi Tower)问题 ——<数据结构>-严蔚敏.吴伟民版        源码使用说明  链接☛☛☛ <数据结构-C语言版> ...

  7. 1028. Hanoi Tower Sequence

    1028. Hanoi Tower Sequence Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Hanoi Tow ...

  8. Python学习札记(十四) Function4 递归函数 & Hanoi Tower

    reference:递归函数 Note 1.在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. eg.计算阶乘: #!/usr/bin/env python3 def ...

  9. zoj 2954 Hanoi Tower

    Hanoi Tower Time Limit: 2 Seconds Memory Limit: 65536 KB You all must know the puzzle named "Th ...

随机推荐

  1. Data Lake Analytics IP白名单设置攻略

    当我们成功开通了 DLA 服务之后,第一个最想要做的事情就是登录 DLA 数据库.而登录数据库就需要一个连接串.下面这个页面是我们首次开通 DLA 之后的界面,在这里我们要创建一个服务访问点. 在上面 ...

  2. QT_获取正在运行程序的进程id(判断程序是否正在运行)

    bool checkProcessRunning(const QString &processName, QList<quint64> &listProcessId) { ...

  3. IO流-文件操作

    一.字节流读/写 文件 1.字节流 方式读取文件

  4. malloc: *** error for object 0x10a291df8: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug

    malloc_error_break错误: .You'll find out what the object is when you break in the debugger. Just look ...

  5. concurrent模块

    concurrent包 concurrent.futrues模块 3.2版本引入 异步并行任务模块,提供一个高级的异步可执行的便利接口. 提供了两个池执行器 ThreadPoolExecutor异步调 ...

  6. iOS:你App的设置做对了吗?

    http://www.cocoachina.com/ios/20151217/14707.html iOS 8及以上版本最不为人知的一个特点是与应用设置的深层链接,用户可以根据APP的需要授权启用位置 ...

  7. JDBC操作数据库实例

    jdbc操作数据库实例 1.jdbc创建数据库 1.1 前提条件 1.拥有创建和删除表的权限 2.数据库已经启动,且可用 1.2 jdbc创建数据库表的步骤: 导包:导入需要进行数据库编程的 JDBC ...

  8. bzoj2424 订货

    Description 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付存贮费用m,假定第一月月初的库存量为零,第n月月底的库存量也为 ...

  9. Python学习之路15☞socket编程

    一 客户端/服务器架构 即C/S架构,包括 1.硬件C/S架构(打印机) 2.软件C/S架构(web服务) C/S架构与socket的关系: 我们学习socket就是为了完成C/S架构的开发 二 os ...

  10. python 捕获异常