关于汉诺塔的递归,记住一个结论是,转移n个盘子至少需要2^n-1步

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std; int two[100005],pos[100005]; int main()
{
int n,nn[5],i,j,ans,now,end,mid,a;
two[0]=1;
for(i=1;i<=100000;i++)
two[i]=(two[i-1]*2)%1000000;
while(~scanf("%d",&n))
{
scanf("%d%d%d",&nn[1],&nn[2],&nn[3]);
for(i=1;i<=3;i++)
{
for(j=1;j<=nn[i];j++)
{
scanf("%d",&a);
pos[a]=i;
}
}
ans=0;
end=now=pos[n];
printf("%d\n",pos[n]);
while(n>0)
{
if(end!=now)
{
ans=(ans+two[n-1])%1000000;
end=mid;
}
n--;
now=pos[n];
mid=6-now-end;
}
printf("%d\n",ans);
}
return 0;
}

poj1920 Towers of Hanoi的更多相关文章

  1. The Towers of Hanoi Revisited---(多柱汉诺塔)

    Description You all must know the puzzle named "The Towers of Hanoi". The puzzle has three ...

  2. [CareerCup] 3.4 Towers of Hanoi 汉诺塔

    3.4 In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes ...

  3. POJ 1958 Strange Towers of Hanoi 解题报告

    Strange Towers of Hanoi 大体意思是要求\(n\)盘4的的hanoi tower问题. 总所周知,\(n\)盘3塔有递推公式\(d[i]=dp[i-1]*2+1\) 令\(f[i ...

  4. POJ 1958 Strange Towers of Hanoi

    Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3784 Accepted: 23 ...

  5. POJ-1958 Strange Towers of Hanoi(线性动规)

    Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2677 Accepted: 17 ...

  6. ural 2029 Towers of Hanoi Strike Back (数学找规律)

    ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺 ...

  7. POJ1958 Strange Towers of Hanoi [递推]

    题目传送门 Strange Towers of Hanoi Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3117   Ac ...

  8. poj 1920 Towers of Hanoi

    Towers of Hanoi Time Limit: 3000MS   Memory Limit: 16000K Total Submissions: 2213   Accepted: 986 Ca ...

  9. zoj 2338 The Towers of Hanoi Revisited

    The Towers of Hanoi Revisited Time Limit: 5 Seconds Memory Limit: 32768 KB Special Judge You all mus ...

随机推荐

  1. Candy Sharing Game(模拟搜索)

    Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. Foundation Sorting: Quicksort

    /* Quick Sorting. * Implementation history:. * 2013-09-15, Mars Fu, first version. */ /* [Quicksort ...

  3. uva Stacks of Flapjacks

                                                     Stacks of Flapjacks  题目链接:Click Here~ 题目描写叙述:     ...

  4. 浅谈web前端开发阅历

    WEB前端研发工程师,在国内算是一个朝阳职业,这个领域没有学校的正轨教育,大多数人都是靠本人自学成才.本文次要引见本人从事web开发以来(从大二至今)看过的书籍和本人的成长过程,目的是给想了解Java ...

  5. ;(function($,window,undefined){})(jQuery,window)详细解析————借助B5教程解析自己整理了一下

    在jquery插件中我们经常看到以下这段代码 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, window,d ...

  6. Codeforces 18C C. Stripe

    Codeforces 18C  C. Stripe 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/E 题 ...

  7. C++之对象组合

    #include<stdio.h>//初始化列表 提供了对成员变量初始化的方式//Constructor        class M      {       private:      ...

  8. poj3693之后缀数组

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5946   Accepted: 1799 Description The r ...

  9. poj 2513

    http://poj.org/problem?id=2513 73348K        1438MS        C++        1614B解题思路:欧拉路的应用 要点 :1.判断连通性   ...

  10. 块元素block,内联元素inline; inline-block;

    block:块元素的特征 div ol li 等: 1.只有高度不设置宽度的时候默认撑满一行: 2.默认块元素不在一行: 3.支持所以CSS命令: inline:内联元素的特征 span i stro ...