poj1920 Towers of Hanoi
关于汉诺塔的递归,记住一个结论是,转移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的更多相关文章
- The Towers of Hanoi Revisited---(多柱汉诺塔)
Description You all must know the puzzle named "The Towers of Hanoi". The puzzle has three ...
- [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 ...
- 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 ...
- POJ 1958 Strange Towers of Hanoi
Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3784 Accepted: 23 ...
- POJ-1958 Strange Towers of Hanoi(线性动规)
Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2677 Accepted: 17 ...
- ural 2029 Towers of Hanoi Strike Back (数学找规律)
ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺 ...
- POJ1958 Strange Towers of Hanoi [递推]
题目传送门 Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3117 Ac ...
- poj 1920 Towers of Hanoi
Towers of Hanoi Time Limit: 3000MS Memory Limit: 16000K Total Submissions: 2213 Accepted: 986 Ca ...
- 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 ...
随机推荐
- 精简版LVCL,有空看看
http://tothpaul.free.fr/sources.php?lvcl.lvcl1 http://synopse.info/forum/viewtopic.php?id=665
- HDU 2138 How many prime numbers
米勒罗宾素数测试: /* if n < 1,373,653, it is enough to test a = 2 and 3. if n < 9,080,191, it is enoug ...
- mysql下的SELECT INTO语句
在mysql下使用SELECT INTO语句会产生ERROR 1327 (42000): Undeclared variable:new_tablename 此时要使用: CREATE TABLE C ...
- HashMap和HashTable 学习
1. HashMap 1) hashmap的数据结构 Hashmap是一个数组和链表的结合体(在数据结构称“链表散列“),如下图示: 当我们往hashmap中put元素的时候,先根据key的hash ...
- EnumMap源代码阅读器
EnumMap是一个用于存放键值为enum类型的map.全部的键值必须来自一个单一的enum类型.EnumMap内部用数组表示效率更高. EnumMap维持键值的自然顺序(即枚举类型常量声明的顺序), ...
- 怎么取消 Windows Server 2012 RDP 限制每个用户只能进行一个会话
在 Windows Server 2008 / 2008 R2 上,如果希望多个远程用户使用同一个账号同时访问服务器的 Remote Desktop(RDP),只需通过管理工具-远程桌面下的“远程桌面 ...
- BCS--设置BDC元数据存储权限--访问被业务数据拒绝
设置元数据存储权限 http://blog.163.com/liangshan_wei@126/blog/static/8297850320139126930290/
- ASP.NET 操作配置文件
1.配置文件的各种操作 http://www.cnblogs.com/shimeng3344518/archive/2007/04/23/723999.html 2. http://www.jb51. ...
- Oracle定时器调用存储过程
1. 创建表 create table job_table(run_time date); 2. 创建存储过程 create or replace procedure job_proc is begi ...
- MySQL支持emoji
方案1: 应用层支持 MySQL默认的数据库编码是utf8,对于emoji文字是不能直接存储的,要想存储emoji,有许多库支持对emoji的转换,例如将