【算法】程序猿不写代码是不对的40
来源:互联网 发布:div into python 编辑:程序博客网 时间:2024/05/18 00:17
package com.kingdz.algorithm.time201704;/** * 某一种网上的非递归汉诺塔解法,解题思路暂时我不清楚 * * @author kingdz * */public class Algo10 {public static void main(String[] args) {int[] level_position = new int[100];int n = 3;int sample_nub = 0;int total_sample = 1;for (int i = 1; i < n; i++) {total_sample *= 2;}for (int i = 0; i <= n; i++) {level_position[i] = 0;}int i = n;level_position[i]++;output(i, level_position[n], n);sample_nub++;while (sample_nub < total_sample) {while (level_position[i] == 2 * level_position[i - 1]) {i--;}level_position[i - 1]++;output(i - 1, level_position[i - 1], n);i = n;level_position[i]++;output(i, level_position[n], n);sample_nub++;}output(1, 1, 1);}private static void output(int present_level, int position, int n) {int val = (position - 1) % 3;if (present_level % 2 == 1) {val = val + 3;}switch (val) {case 0:System.out.println(n - present_level + 1 + "\tfrom A to B");break;case 1:System.out.println(n - present_level + 1 + "\tfrom B to C");break;case 2:System.out.println(n - present_level + 1 + "\tfrom C to A");break;case 3:System.out.println(n - present_level + 1 + "\tfrom A to C");break;case 4:System.out.println(n - present_level + 1 + "\tfrom C to B");break;case 5:System.out.println(n - present_level + 1 + "\tfrom B to A");break;}}}
0 0
- 【算法】程序猿不写代码是不对的40
- 【算法】程序猿不写代码是不对的1
- 【算法】程序猿不写代码是不对的2
- 【算法】程序猿不写代码是不对的3
- 【算法】程序猿不写代码是不对的4
- 【算法】程序猿不写代码是不对的5
- 【算法】程序猿不写代码是不对的6
- 【算法】程序猿不写代码是不对的7
- 【算法】程序猿不写代码是不对的8
- 【算法】程序猿不写代码是不对的9
- 【算法】程序猿不写代码是不对的10
- 【算法】程序猿不写代码是不对的11
- 【算法】程序猿不写代码是不对的12
- 【算法】程序猿不写代码是不对的13
- 【算法】程序猿不写代码是不对的14
- 【算法】程序猿不写代码是不对的15
- 【算法】程序猿不写代码是不对的16
- 【算法】程序猿不写代码是不对的17
- 这些年--这些Android
- 老罗和老罗的9小时专访,11句话概括中心思想!
- c++第四次实验(作业)
- <mvc:annotation-driven/> <context:annotation-config/> <context:component-scan>
- 整理一下项目中一些知识:富文本编辑器
- 【算法】程序猿不写代码是不对的40
- temp
- mybatis如何获取oracle新插入数据记录的主键?
- FPGA经验分享——时序收敛之路
- ubuntu下软件安装
- QT文件路径问题
- 对称的二叉树
- Ubuntu让Mosquitto支持Websocket
- 如何遍历hashmap