Your mission is to move the stack from the left peg to the right peg. The rules are well known:

Only one disk may be moved at a time. Each move consists of taking the upper disk from one of the pegs and sliding it onto another rod, on top of the other disks that may already be present on that rod. No disk may be placed on top of a smaller disk.

And finally to prove that you are a genius and a master of mouse handling, you have a timelimit of 60 seconds.

这是一个汉诺塔游。要求60秒内完成。(以我单身xx年的手速都无法完成...)

下载这个 java applet, 反编译。

每移动一个会向服务器发送一个请求 (像:?query=ab; ?query=cb),返回对应的编码,将返回的数据append到 StringBuffer变量solution中。最后solution进入SHA512后,提交?solution= SHA512(solution)

query 对应的返回值是:

ab    we
ac    ch
ba    lr
bc    al
ca    ul
cb    z!

ab表示 将 a柱中最上面的柱移动到b柱的最上面。其它同理。

然后就是求解汉诺塔了,是一个递归的过程。

import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map; public class Main {
static Map<String, String> query;
static StringBuffer solution; /**
* 汉诺递归
*
* @param a
* --源柱子
* @param b
* --中间临时可存放的柱子
* @param c
* --目标术子,要搬运到的柱子
* @param n
* --源柱子有n个柱子
*/
private static void foo(char a, char b, char c, int n) {
if (n == 1) {
solution.append(query.get("" + a + c));
return;
}
foo(a, c, b, n - 1);
solution.append(query.get("" + a + c));
foo(b, a, c, n - 1);
} public static String SHA512(String s) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-512");
byte[] pt = s.getBytes();
byte[] ct = digest.digest(pt);
return bytesToHex(ct);
} catch (Exception e) {
}
return null;
} public static String bytesToHex(byte[] data) {
if (data == null) {
return null;
}
int len = data.length;
StringBuffer hexString = new StringBuffer(len * 2);
for (int i = 0; i < len; i++) {
if ((data[i] & 0xFF) < 16) {
hexString.append(0);
}
hexString.append(Integer.toHexString(data[i] & 0xFF));
}
return hexString.toString();
} public static void main(String[] args) {
int n = 10;
query = new HashMap<String, String>();
query.put("ab", "we");
query.put("ac", "ch");
query.put("ba", "lr");
query.put("bc", "al");
query.put("ca", "ul");
query.put("cb", "z!");
solution = new StringBuffer();
foo('a', 'b', 'c', n);
System.out.println(SHA512(solution.toString()));
}
}

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 ...

  10. poj1958——Strange Towers of Hanoi

    The teacher points to the blackboard (Fig. 4) and says: "So here is the problem: There are thre ...

随机推荐

  1. Nginx-uri、request_uri、document_uri之间的区别

    在nginx中有几个关于uri的变量,包括$uri.$request_uri.$document_uri,下面看一下他们的区别 :$request_uri: /stat.php?id=1585378& ...

  2. [洛谷OJ] P1114 “非常男女”计划

    洛谷1114 “非常男女”计划 本题地址:http://www.luogu.org/problem/show?pid=1114 题目描述 近来,初一年的XXX小朋友致力于研究班上同学的配对问题(别想太 ...

  3. angular+bootstrap+MVC--之一,入门

    这篇直奔MVVM主题,本例实现一个bootstrap的下拉框. 展示了如下技术: 1.MVVM绑定(事件绑定,值绑定,循环绑定,循环绑定中嵌套事件并回传item), 2.angul多module, 建 ...

  4. python---dict字典

    Python 字典 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格式 ...

  5. Eclipse插件SVN配置

    Eclipse插件SVN配置 方法一 打开Eclipse点击[Help]-[Install New Software] 点击右边[Add]-在弹出窗口中输入 Name:svn Location:htt ...

  6. c#获取枚举

    在实际开发项目中,我们定义了一个枚举,往往我们需要在下拉框或其它地方展示枚举.为了加深印象,也为了帮到有需要的人,我写了一个DEMO. 第一步,我们定义一个枚举: /// <summary> ...

  7. MyEclipse中查询

    在当前文件中查询: Ctrl + F 在整个项目中查询:   Ctrl + H(选File Search)

  8. 甲状腺癌怎样早发现 可B超检查

    2013-12-13 14:40:00.0 本文来源:人民网 点击参与跟帖 原标题:健康之道:甲状腺癌怎样早发现 摘要:甲状腺癌怎样早发现呢?隐早期以甲状腺结节的方式存在,且以匿方式生长,可能在人们偶 ...

  9. 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败

    .NET导出Excel遇到的80070005错误的解决方法: 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出 ...

  10. 关于Unity中Camera的Aspect

    一直以来对Camera的Aspect和Game窗口的Aspect都是一知半解,某天从一本书中看到了对Camera的API讲解,但是总觉得对Aspect讲解的有问题.于是就认真的思考起了这个问题,还发现 ...