首页 技术 正文
技术 2022年11月11日
0 收藏 1000 点赞 2,580 浏览 1833 个字

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.

Towers of Hanoi

这是一个汉诺塔游。要求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()));
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,110
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,202
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,837
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,920