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()));
}
}

最新文章

  1. git 安装与配置
  2. Spring - 初始化spring容器
  3. acess the C\c++ from the Java
  4. jquery easyui DataGrid
  5. 如何向VS2010中插入ActiveX控件并且附带相应的类
  6. Logistic Regression(逻辑回归)(二)—深入理解
  7. SQL2005性能分析一些细节功能你是否有用到?(二)
  8. namenode ha
  9. FFmpeg源代码简单分析:avcodec_close()
  10. Hive 特殊日期获取 tips
  11. OneZero第三周第三次站立会议(2016.4.6)
  12. 12.使用default-Action配置统一访问
  13. ahk打印成pdf记录
  14. python 多线程简介
  15. HDU 3172 Virtual Friends(map+并查集)
  16. spring的AOP动态代理--JDK代理和CGLIB代理区分以及注意事项
  17. mui 的多图片上传
  18. Linux安装防火墙
  19. Python爬虫|爬取喜马拉雅音频
  20. Java 线程池ThreadPoolExecutor简单应用

热门文章

  1. JQUERY添加、删除元素、eq()方法;
  2. windows下面安装Python和pip
  3. VISIBLE、INVISIBLE、GONE的区别
  4. Artificial-Intelligence BOOKs
  5. Nginx 下配置SSL证书的方法
  6. MapReduce简介
  7. 聊一下JS中的作用域scope和闭包closure
  8. input 只读不能修改
  9. [驱动]内核添加USB转串口驱动支持
  10. MemcacheQ 安装与使用