笔试+刷题-图论

qunar2019马在8*8棋盘上从A到B最短需要几步(DFS)

package com.qunar;

import java.util.Scanner;

public class Main21 {
	private static Scanner input =new Scanner(System.in);
	private static int x1=input.nextInt();
	private static int y1=input.nextInt();
	private static int x2=input.nextInt();
	private static int y2=input.nextInt();
	private static int res=Integer.MAX_VALUE;
	private static boolean[][] marked=new boolean[9][9];
	private static int[][] dir=new int[][] {{1,2},{1,-2},{-1,2},{-1,-2},
											{2,1},{2,-1},{-2,1},{-2,-1}};

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int step=0;
		dfs(x1,y1,0);
		System.out.println(res);

	}

	private static void dfs(int x, int y,int step) {
		// TODO Auto-generated method stub
		if (step=1&&tmpx<=8&&tmpy>=1&&tmpy<=8&&!marked[tmpx][tmpy]) {
						marked[tmpx][tmpy]=true;
						dfs(tmpx,tmpy,step+1);
						marked[tmpx][tmpy]=false;
					}
				}
			}
			
		}
	}

}

 

你可能感兴趣的:(求职笔试)