第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

青蛙過河問題!注釋寫的不咋地,有錯誤。希望大神解釋這個程序的rollback()和record()方法怎么算的?

青蛙過河問題!注釋寫的不咋地,有錯誤。希望大神解釋這個程序的rollback()和record()方法怎么算的?

Arnao 2017-08-30 19:56:50
package com.demo.hwj.javademo.kotlin;import java.util.Arrays;//要使用工具類;public class Testing { static int[] mInput = {1, 2, 3, 0, 9, 10, 11};//這是之前的順序;這里靜態(tài)的作用便是方便之后復(fù)制;? ? static int[] mStep = new int[100];//步數(shù)? ? static int[] mResult = {9, 10, 11, 0, 1, 2, 3};//這是之后的順序? ? static int mBridgeIndex = 0;//中間的坐標(biāo)? ? static int[] mLeft = null;//左邊操作的數(shù)組? ? static int[] mRight = null;//右邊操作的數(shù)組? ? static int stepPosition = 0;//當(dāng)前步的坐標(biāo)? ? public static void main(String[] args) {? ? ? ? init();//初始化? ? ? ? start();//開始? ? }? ? private static void start() {? ? ? ? do {? ? ? ? ? ? switch (mStep[stepPosition]) {? ? ? ? ? ? ? ? case 1:? ? ? ? ? ? ? ? ? ? if (move(1, 1)) {? ? ? ? ? ? ? ? ? ? ? ? break;? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? case 2:? ? ? ? ? ? ? ? ? ? if (move(1, 2)) {? ? ? ? ? ? ? ? ? ? ? ? break;? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? case 3:? ? ? ? ? ? ? ? ? ? if (move(2, 1)) {? ? ? ? ? ? ? ? ? ? ? ? break;? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? case 4:? ? ? ? ? ? ? ? ? ? if (!move(2, 2)) {? ? ? ? ? ? ? ? ? ? ? ? //reset mInput ,rollback mStep? ? ? ? ? ? ? ? ? ? ? ? rollback();? ? ? ? ? ? ? ? ? ? ? ? continue;? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? }? ? ? ? ? ? stepPosition++;? ? ? ? } while (!Arrays.equals(mResult, mInput));? ? ? ? outputStep();? ? }? ??//這個方法就是輸出運動的實況吧;? ??? ? private static void outputStep() {? ? ? ? int[] finallyStep = Arrays.copyOf(mStep, stepPosition);? ? ? ? reset();//? ? ? ? for (int i = 0; i < finallyStep.length; i++) {? ? ? ? ? ? switch (finallyStep[i]) {? ? ? ? ? ? ? ? case 1:? ? ? ? ? ? ? ? ? ? moveLeft(1);? ? ? ? ? ? ? ? ? ? System.out.printf(i + ": ?Left walking =>" + Arrays.toString(mInput) + "\n");? ? ? ? ? ? ? ? ? ? break;? ? ? ? ? ? ? ? case 2:? ? ? ? ? ? ? ? ? ? moveLeft(2);? ? ? ? ? ? ? ? ? ? System.out.printf(i + ": ?Left jumping =>" + Arrays.toString(mInput) + "\n");? ? ? ? ? ? ? ? ? ? break;? ? ? ? ? ? ? ? case 3:? ? ? ? ? ? ? ? ? ? moveRight(1);? ? ? ? ? ? ? ? ? ? System.out.printf(i + ": ?Right walking =>" + Arrays.toString(mInput) + "\n");? ? ? ? ? ? ? ? ? ? break;? ? ? ? ? ? ? ? case 4:? ? ? ? ? ? ? ? ? ? moveRight(2);? ? ? ? ? ? ? ? ? ? System.out.printf(i + ": ?Right jumping =>" + Arrays.toString(mInput) + "\n");? ? ? ? ? ? ? ? ? ? break;? ? ? ? ? ? }? ? ? ? }? ? }//這是初始化,初始化游戲的;? ? private static void init() {? ? ? ? mBridgeIndex = mInput.length / 2;// get middle bridge's position,用來獲取中間的坐標(biāo);? ? ? ? mLeft = Arrays.copyOfRange(mInput, 0, mBridgeIndex);//將左邊的數(shù)組用Arrays工具類的copy of range()方法將從0到中間復(fù)制到新數(shù)組中;? ? ? ? mRight = Arrays.copyOfRange(mInput, mBridgeIndex + 1, mInput.length);//同左;? ? ? ? Arrays.fill(mStep, 1);//將Setp數(shù)組用1填充;? ? }? ? /**? ? ?* move input child element .include all the way for move? ? ?*? ? ?* @param direction ? ?the direction for move. ?1 means left,2 means right? ? ?* @param stepInterval the way for move. 1 means walking,2 means jumping? ? ?*/? ? //這是運動的總類,包含了所有的移動方式;? ? private static boolean move(final int direction, final int stepInterval) {? ? //這里主要是發(fā)現(xiàn)是否有異常;? ? ? ? if (stepInterval != 1 && stepInterval != 2)? ? ? ? ? ? new IllegalArgumentException(" stepInterval must equal 1 or 2. ?-----> line 65");? ? ? ? if (direction != 1 && direction != 2)? ? ? ? ? ? new IllegalArgumentException(" direction must equal 1 or 2.-----> line 65");? ? ? ? boolean isWalking;? ? ? ? //這里要判斷移動的方式,有跳和走,有左有右? ? ? ? if (direction == 1) {? ? ? ? ? ? isWalking = moveLeft(stepInterval);? ? ? ? } else {? ? ? ? ? ? isWalking = moveRight(stepInterval);? ? ? ? }? ? ? ? //當(dāng)被指向時候進(jìn)行判斷;? ? ? ? if (isWalking) {? ? ? ? ? ? //record down step? ? ? ? ? ? record(direction, stepInterval);? ? ? ? }? ? ? ? return isWalking;? ? }? ? private static void record(int direction, int step) {? ? ? ? ? ? switch (direction) {? ? ? ? ? ? case 1:? ? ? ? ? ? ? ? mStep[stepPosition] = direction * step;? ? ? ? ? ? ? ? break;? ? ? ? ? ? case 2:? ? ? ? ? ? ? ? mStep[stepPosition] = direction + step;? ? ? ? ? ? ? ? break;? ? ? ? }? ? }? ? private static void rollback() {? ? ? ? if (mStep[stepPosition] >= 4) {? ? ? ? ? ? mStep[stepPosition] = 1;? ? ? ? ? ? stepPosition--;? ? ? ? }? ? ? ? if (stepPosition < 0)?? ? ? ? stepPosition = 0;? ? ? ? if (mStep[stepPosition] < 4) {? ? ? ? ? ? mStep[stepPosition]++;? ? ? ? ? ? reset();? ? ? ? }? ? }? ? /**? ? ?* move input child element .include ?the way for move is Left? ? ?*? ? ?* @param stepInterval the way for move. 1 means walking,2 means jumping? ? ?* @return if return false that means cannot moving? ? ?*/? ? //左向的方法? ? private static boolean moveLeft(final int stepInterval) {? ? ? ? for (int i = 0; i < mInput.length; i++) {? ? ? ? ? ? if (containOf(mLeft, mInput[i])) {// search item whether inside for mInput? ? ? ? ? ? ? ? if (i < mInput.length - stepInterval && mInput[i + stepInterval] == 0) {? ? ? ? ? ? ? ? ? ? //change item? ? ? ? ? ? ? ? ? ? int a = mInput[i];? ? ? ? ? ? ? ? ? ? mInput[i + stepInterval] = a;? ? ? ? ? ? ? ? ? ? mInput[i] = 0;? ? ? ? ? ? ? ? ? ? return true;? ? ? ? ? ? ? ? }? ? ? ? ? ? }? ? ? ? }? ? ? ? return false;? ? }? ? //右向的方法? ? private static boolean moveRight(final int stepInterval) {? ? ? ? for (int i = mInput.length - 1; i >= 0; i--) {? ? ? ? ? ? if (containOf(mRight, mInput[i])) {// search item whether inside for mInput? ? ? ? ? ? ? ? if (i >= 0 + stepInterval && mInput[i - stepInterval] == 0) {? ? ? ? ? ? ? ? ? ? //change item? ? ? ? ? ? ? ? ? ? mInput[i - stepInterval] = mInput[i];? ? ? ? ? ? ? ? ? ? mInput[i] = 0;? ? ? ? ? ? ? ? ? ? return true;? ? ? ? ? ? ? ? }? ? ? ? ? ? }? ? ? ? }? ? ? ? return false;? ? }? ? private static boolean containOf(int[] arr, int child) {? ? ? ? for (int i : arr) {? ? ? ? ? ? if (i == child)?? ? ? ? ? ? return true;? ? ? ? }? ? ? ? return false;? ? }? ? private static void reset() {? ? ? ? mInput[0] = 1;? ? ? ? mInput[1] = 2;? ? ? ? mInput[2] = 3;? ? ? ? mInput[3] = 0;? ? ? ? mInput[4] = 4;? ? ? ? mInput[5] = 5;? ? ? ? mInput[6] = 6;? ? ? ? stepPosition = 0;? ? }}
查看完整描述

1 回答

?
慕標(biāo)5263832

TA貢獻(xiàn)11條經(jīng)驗 獲得超3個贊

太長不閱

查看完整回答
反對 回復(fù) 2017-08-31
  • 1 回答
  • 0 關(guān)注
  • 1070 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號