Go to diff to previous submission
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.ArrayDeque; import java.util.Queue; import java.util.Scanner; /** * * @author cteam051 */ public class Grashopper { public static class Bod{ private int x,y,vzdal; public Bod(int x, int y, int vzdal) { this.x = x; this.y = y; this.vzdal = vzdal; } } public static int [][]stav; //public static int [][]vzdalenost; public static boolean konec; public static int val; public static int X, Y, StartX, StartY, CilX, CilY; public static Queue<Bod> fronta; stav = new int [104][104]; fronta = new ArrayDeque<Bod>(); //vzdalenost = new int [102][102]; while (sc.hasNextInt()){ fronta.clear(); konec = false; X = sc.nextInt()+2; Y = sc.nextInt()+2; StartX = sc.nextInt()+1; StartY = sc.nextInt()+1; CilX = sc.nextInt()+1; CilY = sc.nextInt()+1; val = -1; for (int i=2; i<X; i++){ for (int j=2; j<Y; j++){ stav[i][j]=0; } } int TempX=X+2; int TempY=Y+2; for (int i=0; i<2; i++){ for (int j=0; j<TempY; j++){ stav[i][j]=1; stav[i+X][j]=1; } } for (int i=0; i<TempX; i++){ for (int j=0; j<2; j++){ stav[i][j]=1; stav[i][j+Y]=1; } } fronta.add(new Bod(StartX,StartY,0)); bf1(); if (val==-1){ } else { } } } public static void bf1(){ Bod temp; while(true){ if (konec == true || fronta.isEmpty())return; temp=fronta.remove(); bf(temp.x, temp.y, temp.vzdal); } } public static void bf(int x, int y,int vzdal){ if (x == CilX && y == CilY) { konec = true; val = vzdal; return; } stav[x][y]=1; //System.out.println(x + " " + y); if (stav[x+1][y+2]==0){ fronta.add(new Bod(x+1,y+2,vzdal+1)); } if (stav[x+2][y+1]==0){ fronta.add(new Bod(x+2, y+1,vzdal+1)); } if (stav[x+2][y-1]==0){ fronta.add(new Bod(x+2, y-1,vzdal+1)); } if (stav[x+1][y-2]==0){ fronta.add(new Bod(x+1, y-2,vzdal+1)); } if (stav[x-1][y+2]==0){ fronta.add(new Bod(x-1, y+2,vzdal+1)); } if (stav[x-1][y-2]==0){ fronta.add(new Bod(x-1, y-2,vzdal+1)); } if (stav[x-2][y+1]==0){ fronta.add(new Bod(x-2, y+1,vzdal+1)); } if (stav[x-2][y-1]==0){ fronta.add(new Bod(x-2, y-1,vzdal+1)); } } }
--- c4.s812.cteam051.grasshop.java.0.Grashopper.java +++ c4.s825.cteam051.grasshop.java.0.Grashopper.java @@ -39,5 +39,5 @@ public static void main(String[] args) { Scanner sc = new Scanner(System.in); - stav = new int [102][102]; + stav = new int [104][104]; fronta = new ArrayDeque<Bod>(); //vzdalenost = new int [102][102];