Go to diff to previous submission
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.LinkedList; import java.util.List; import java.util.Scanner; /** * * @author cteam041 */ public class grasshop { int R, C, Gr, Gc, Lr, Lc; while (sc.hasNextInt()) { List<Pos> q = new LinkedList<Pos>(); R = sc.nextInt(); C = sc.nextInt(); Gr = sc.nextInt()-1; Gc = sc.nextInt()-1; Lr = sc.nextInt()-1; Lc = sc.nextInt()-1; Pos start = new Pos(); start.r = Gr; start.c = Gc; start.iter = 1; q.add(start); int[][] pole = new int[R][C]; pole[Gc][Gr] = 1; int iter = 1; boolean found = false; while (q.size() > 0) { Pos k = q.get(0); q.remove(0); iter = k.iter; if (Lr == k.r && Lc == k.c) { found = true; break; } int i = k.c; int j = k.r; int x = i + 2; int y = j + 1; if (x >= 0 && x < C && y >= 0 && y < R) { if (pole[x][y] == 0) { Pos n = new Pos(); n.c = x; n.r = y; n.iter = iter+1; q.add(n); pole[x][y]=n.iter; } } x = i - 2; y = j + 1; if (x >= 0 && x < C && y >= 0 && y < R) { if (pole[x][y] == 0) { Pos n = new Pos(); n.c = x; n.r = y; n.iter = iter+1; q.add(n); pole[x][y]=n.iter; } } x = i - 2; y = j - 1; if (x >= 0 && x < C && y >= 0 && y < R) { if (pole[x][y] == 0) { Pos n = new Pos(); n.c = x; n.r = y; n.iter = iter+1; q.add(n); pole[x][y]=n.iter; } } x = i + 2; y = j - 1; if (x >= 0 && x < C && y >= 0 && y < R) { if (pole[x][y] == 0) { Pos n = new Pos(); n.c = x; n.r = y; n.iter = iter+1; q.add(n); pole[x][y]=n.iter; } } //opacnefound?:" x = i + 1; y = j + 2; if (x >= 0 && x < C && y >= 0 && y < R) { if (pole[x][y] == 0) { Pos n = new Pos(); n.c = x; n.r = y; n.iter = iter+1; q.add(n); pole[x][y]=n.iter; } } x = i - 1; y = j + 2; if (x >= 0 && x < C && y >= 0 && y < R) { if (pole[x][y] == 0) { Pos n = new Pos(); n.c = x; n.r = y; n.iter = iter+1; q.add(n); pole[x][y]=n.iter; } } x = i - 1; y = j - 2; if (x >= 0 && x < C && y >= 0 && y < R) { if (pole[x][y] == 0) { Pos n = new Pos(); n.c = x; n.r = y; n.iter = iter+1; q.add(n); pole[x][y]=n.iter; } } x = i + 1; y = j - 2; if (x >= 0 && x < C && y >= 0 && y < R) { if (pole[x][y] == 0) { Pos n = new Pos(); n.c = x; n.r = y; n.iter = iter+1; q.add(n); pole[x][y]=n.iter; } } } if (!found) } } } class Pos { public int r, c, iter; }
--- c4.s936.cteam041.grasshop.java.0.Grasshop.java +++ c4.s944.cteam041.grasshop.java.0.grasshop.java @@ -14,9 +14,5 @@ * @author cteam041 */ -public class Grasshop { - - /**eam/index.php?submitted=728 - * @param args the command line arguments - */ +public class grasshop { public static void main(String[] args) {