Towers of Hanoi
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的更多相关文章
- 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 ...
- poj1958——Strange Towers of Hanoi
The teacher points to the blackboard (Fig. 4) and says: "So here is the problem: There are thre ...
随机推荐
- opencv配置(2.49)
转载自浅墨大神http://blog.csdn.net/poem_qianmo/article/details/19809337 OpenCV2.4.9和2.4.8的配置几乎一样,唯一的区别在下文中的 ...
- C语言编译和链接过程
1.程序的编译 一般而言,大多数编译系统都提供编译驱动程序(complier driver),根据用户需求调用语言预处理器,编译器,汇编器和链接器.例如有如下历程://main.c void swa ...
- EDIUS中调整YUV曲线的教程
本篇文章重点地讲解了EDIUS调整YUV曲线的方法,是一篇很详细的EDIUS教程文章,它能帮助新手小伙伴快速掌握EDIUS视频编辑软件的某一知识点.相信坚持学习小编推荐的教程文章,你们会很快入门EDI ...
- 学习laravel之路由问题 404
今天配置路由的时候,只有原来的自带路由可用: Route::get('/', function(){ return View::make('hello');}); 再网上搜索了办法:来自:htt ...
- shiro 标签
在使用Shiro标签库前,首先需要在JSP引入shiro标签: <%@ taglib prefix="shiro" uri="http://shiro.apache ...
- jQuery入门级part.2
一,事件编程 基本事件: blur(fn) 当失去焦点时 change(fn) 当内容发生改变时 click(fn) 当鼠标单击时 dblclick(fn) 当鼠标双击时 focus ...
- PHPMyAdmin 显示缺mysqli 扩展的解决方法
今天在学PHP100视频教程时,装了phpMyAdmin.一开始下载的是最新版本phpMyAdmin-4.1.4-all-languages, 直接500错误,页面怎么也打不开.我用的PHP版本是老版 ...
- overfitting过拟合
来自:https://www.zhihu.com/question/32246256 其实不完全是噪声和假规律会造成过拟合. (1)打个形象的比方,给一群天鹅让机器来学习天鹅的特征,经过训练后,知道了 ...
- Python中利用LSTM模型进行时间序列预测分析
时间序列模型 时间序列预测分析就是利用过去一段时间内某事件时间的特征来预测未来一段时间内该事件的特征.这是一类相对比较复杂的预测建模问题,和回归分析模型的预测不同,时间序列模型是依赖于事件发生的先后顺 ...
- Django进阶篇(一)
Form django中的Form一般有两种功能: 1.输入html 2.验证用户输入 最简易的form验证: <!DOCTYPE html> <html lang="en ...