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. 七.RBM受限玻尔兹曼机

    1.受限玻尔兹曼机   玻尔兹曼机是一大类的神经网络模型,但是在实际应用中使用最多的则是受限玻尔兹曼机(RBM). 受限玻尔兹曼机(RBM)是一个随机神经网络(即当网络的神经元节点被激活时会有随机行为 ...

  2. VMware workstation12安装苹果虚拟机

    一.前言--准备工作 在win10上安装Mac虚拟机,既是费劲又是费内存的活儿 1.安装Vmware 2.下载MacOS的镜像:自行百度下载 3. unlocker的下载地址:http://downl ...

  3. _STORAGE_WRITE_ERROR_:./Application/Runtime/Cache/Home/f8995a0e1afcdadc637612fae5a3b585.php

    将one think部署到服务器上出现下面的问题 _STORAGE_WRITE_ERROR_:./Application/Runtime/Cache/Home/f8995a0e1afcdadc6376 ...

  4. 移动端h5禁用浏览器左滑右滑的前进后退功能

    在项目运行过程中发现,用户在有左右滑动前进后退的功能的浏览器上签字时,偶然触发了前进后退会导致canvas像是重置了一样内容消失,所以需要在代码中处理这种情况. 基本原理就是在touchmove事件中 ...

  5. 介绍Provide以及Inject

    介绍 Vue 的 Provide 以及 Inject Provide 以及 Inject 是 Vue 中用于祖先元素向其所有后台元素注入依赖的接口. 具体用法 // Data.vue ... expo ...

  6. Leetcode687.Longest Univalue Path最长同值路径

    给定一个二叉树,找到最长的路径,这个路径中的每个节点具有相同值. 这条路径可以经过也可以不经过根节点. 注意:两个节点之间的路径长度由它们之间的边数表示. 示例 1: 输入: 5 / \ 4 5 / ...

  7. pytest fixture 利用 params参数实现用例集合

    @pytest.fixture有一个params参数,接受一个列表,列表中每个数据都可以作为用例的输入.也就说有多少数据,就会形成多少用例.如下面例子,就形成3条用例 test_parametrizi ...

  8. PAT天梯赛L1-002 打印漏斗

    题目链接:点击打开链接 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ***** 所谓"沙漏形 ...

  9. CSS面试题总结2(转)

    1.你最喜欢的图片替换方法是什么,你如何选择使用. 图像替代,就是像我们在平时将文本添加到文本中,然后通过css隐藏文本并在它的位置上显示一个背景图片,这样,搜索引擎仍然可以搜到HTML文本,即使我们 ...

  10. Codeforces 414B

    题目链接 附上代码: #include<cstdio> #include<cstring> #include<bits/stdc++.h> #define mod ...