关于汉诺塔的递归,记住一个结论是,转移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. Linux设置高分辨率后无法进入X系统

    Vmware9.0中Xubuntu分辨率从800x600变更为1366x768后在用户输入密码登录后会自动退出x系统,出现这种情况时可以切换到命令行登录界面,然后将-/.config/xfce4/xf ...

  2. hql中不能写count(1)能够写count(a.id)

    hql中不能写count(1)能够写count(a.id)里面写详细的属性 String hql="select new com.haiyisoft.vo.entity.cc.repo.Bu ...

  3. 令人作呕的OpenSSL

    在OpenSSL心脏出血之后,我相信非常多人都出了血,而且流了泪...网上瞬间出现了大量吐嘈OpenSSL的文章或段子,仿佛内心的窝火一瞬间被释放了出来,跟着这场疯闹,我也吐一下嘈,以雪这些年被Ope ...

  4. Live Writer Test

    测试下LiveWriter写CNblog: 1.Source code plug-in: @Override public List getAll(String orgid,String start, ...

  5. 关于css里的class和id

    id 是唯一的 权重100 相当于身份证 只能有一张. class 可以多个元素都拥有 权重10 就相当于电影票 你有我也有. 用法如下 <divid="box">变颜 ...

  6. CSS样式表基础知识、样式表的分类及选择器

    一.CSS基本概念: CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页. /*注释区域*/    此为注释语法 二.样式表的分类 1.内联样式表(和html联合 ...

  7. 关于SOQL(一)

    SOQL 是Salesforce中的查询语言,他的全称是Salesforce Object Query Language. 从字面上就能够看出,这个语言是一种基于对象的查询语言. 在Salesforc ...

  8. Value Categories

    Value categories Three primary categories primary categories mixed special Each C++ expression (an o ...

  9. Linux下载文件时报错 To connect to ohse.de insecurely, use ‘--no-check-certificate’.

    远程调用下载文件直接用wget就可以,一般文件路径类型是http.如果有遇到是https就会下载出错. 错误如下: [root@vmu010226-node1 tmp]# wget https://w ...

  10. cocos2dx进阶学习之CCTMXLayer

    继承关系 CCTMXLayer -> CCSpriteBatchNode CCTMXLayer是在瓦片地图中,抽象一个层的类,它继承自CCSpriteBatchNode,也就是说它抽象了一批相同 ...