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. jQuery的deferred对象使用详解【转载】

    一.什么是deferred对象? 开发网站的过程中,我们经常遇到某些耗时很长的javascript操作.其中,既有异步的操作(比如ajax读取服务器数据),也有同步的操作(比如遍历一个大型数组),它们 ...

  2. Python中 sys.argv的用法简明解释

    Python中 sys.argv[]的用法简明解释 sys.argv[]说白了就是一个从程序外部获取参数的桥梁,这个“外部”很关键,所以那些试图从代码来说明它作用的解释一直没看明白.因为我们从外部取得 ...

  3. vue使用flexible和px2rem实现移动端适配

    首先下载flexible.js和px2rem npm install px2rem-loader 对webpack进行配置.进入build文件夹对utils.js中的postcssLoader做如下修 ...

  4. Collection Iterator 迭代器

    Collection c=new ArrayList(); c.add(123); //迭代器遍历集合 Iterator i=c.Iterator(); while(i.hasNext()) { Sy ...

  5. iOS开发之NSRunLoop的进一步理解

    http://www.cnblogs.com/pengyingh/articles/2343920.html iPhone应用开发中关于NSRunLoop的概述是本文要介绍的内容,NSRunLoop是 ...

  6. C++程序设计教材目录思维导图(增C++Primer)

    正在做C++思维导图,大工程,比较艰苦. 先做了三个C++教材目录的思维导图.C++教材不等于C++,这个容易些.看思维导图,整理所学知识,这个可以会. 给出三张图,对应三种教材: 谭浩强. C++程 ...

  7. kubernetes1.5新特性跟踪(续)

    Kubernetes发布历史回顾 Kubernetes 1.0 - 2015年7月发布 Kubernetes 1.1 - 2015年11月发布 Kubernetes 1.2 - 2016年3月发布 K ...

  8. 一.数据结构&算法的引言+时间复杂度

    目录(contents): 1.什么是计算机科学?什么是算法? 2.如何形象化的理解算法? 3.什么是算法分析? 4.时间复杂度 5.数据结构 6.总结算法和数据结构之间的关联 一.什么是计算机科学? ...

  9. 了解apache与tomcat的关系

    较多的了解过apache,但对tomcat却了解不多: 使用LAMP构建网站毕竟还是有很大局限,越来越多的网站将给予java构建了. http://developer.51cto.com/art/20 ...

  10. poj3422 最小费用流

    一遍的话秩序要dp就好,但是这里要删去点.此题可以转化为最小费用流.开始我想了半天纠结怎么处理到过一次后值变0,看了书之后发现拆点解决了这个问题. 对于点t,拆为t-->t',容量为1,费用为负 ...