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. 对于MD5加密处理方式

    来源:http://blog.51cto.com/xqtesting/1924977 但有时候我们请求的参数可能需要加密,比如登录接口中的密码可能需要经过md5加密这时候怎么处理呢? 这种方法比较简单 ...

  2. ConvertJavaMiliSecondToDateTime

    private static DateTime ConvertJavaMiliSecondToDateTime(long javaMS)        {            DateTime UT ...

  3. html(),val(),text()的区别

    .html(),.text(),.val() 三种方法都是用来读取选定元素的内容: .html()是用来读取元素的HTML内容(包括其Html标签): .text()用来读取元素的纯文本内 容,包括其 ...

  4. 在APPfuse中配置log4j进行定位

    appFuse使用log4j进行日志输出,默认日志级别为warn,输出到串口console. 一下修改为debug级别,输出到串口及文件中: 1.修改(tomcat中的页面根目录)/appfuse/W ...

  5. 将数组对象转换成DataSet

    public static DataSet ObjectArrayToDataSet(object[] objArr) { if (objArr.Length == 0) return null; D ...

  6. C++中delete this

    Is it legal (and moral) for a member function to say delete this? As long as you’re careful, it’s ok ...

  7. MVC设计之MVC设计模式(介绍)

    mvc介绍; 首先先引用一个百度百科的介绍: MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用 ...

  8. Linux下的python安装

    centos7安装python3 以及tab补全功能   1.安装python3 1.1下载python源码包 网址:https://www.python.org/downloads/release/ ...

  9. Java练习 SDUT-3338_计算各种图形的周长(接口与多态)

    计算各种图形的周长(接口与多态) Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 定义接口Shape,定义求周长的方法l ...

  10. Implement strStr() 字符串匹配

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...