Go to diff to previous submission
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package kon; import java.awt.Point; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; /** * * @author student */ public class Kon { private static boolean[][] map; private static int sx, sy, rx, ry, ex, ey; private static Queue<Point> st; private static int sol; int[][] podm = {{1,2},{2,1},{2, -1},{1,-2}, {-1,-2}, {-2,-1},{-2,1},{-1,2}}; while(sc.hasNextInt()) { rx = sc.nextInt(); ry = sc.nextInt(); sx = sc.nextInt(); sy = sc.nextInt(); ex = sc.nextInt(); ey = sc.nextInt(); st = new LinkedList<Point>(); map = new boolean[rx+1][ry+1]; sol = 1; map[sx][sy] = true; st.offer(null); if(sx == ex && sy == ey) { } else { while(true) { if(st.size() == 1) { break; } if(p == null) { st.add(null); sol++; continue; } int x, y; boolean mimo = false; for(int j=0; j<8; j++) { x = p.x + podm[j][0]; y = p.y + podm[j][1]; if(0 < x && x <= rx && 0 < y && y <= ry) { mimo = solve(x, y); if(mimo) break; } } if(mimo) break; } } } } private static boolean solve(int x, int y) { if(!map[x][y]) { if(x == ex && y == ey) { return true; } else { map[x][y] = true; } } return false; } }