Go to diff to previous submission
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Grasshop { public static int maxX; public static int maxY; public static void rekurze(int[][] pole, int x, int y, int hodnota) { if (hodnota > 6) return; if (x<0) return; if (x>=maxX) return; if (y<0) return; if (y>=maxY) return; else { if ((pole[x][y] > hodnota) || (pole[x][y] == 0)) { pole[x][y] = hodnota; rekurze(pole, x+2, y+1, hodnota+1); rekurze(pole, x-2, y+1, hodnota+1); rekurze(pole, x+2, y-1, hodnota+1); rekurze(pole, x-2, y-1, hodnota+1); rekurze(pole, x+1, y+2, hodnota+1); rekurze(pole, x-1, y+2, hodnota+1); rekurze(pole, x+1, y-2, hodnota+1); rekurze(pole, x-1, y-2, hodnota+1); } } } boolean prvni = true; while (true) { try { String linka; linka = bfr.readLine(); if (linka == null) break; if (ln.length < 6) break; /* if (!prvni) System.out.println(); prvni = false; */ if ((sX == cX) && (sY == cY)) { continue; } if ((maxX < 2) || (maxY < 2)) { continue; } int[][] pole = new int[maxX][maxY]; rekurze(pole, cX, cY, 0); pole[cX][cY] = 9; //pole[sX][sY] = 7; /* for(int i=0; i<maxY; i++) { for(int j=0; j<maxX; j++) { System.out.print(pole[j][i]+" "); } System.out.println(); } */ int pocetSkoku = 0; while (pole[sX][sY] == 0) { pocetSkoku++; pole[sX][sY] = 8; int rozX = cX-sX; int rozY = cY-sY; break; } int skX, skY; if (rozX > 0) skX = 2; else skX = -2; if (rozY == 0) { if ((sY-1) < 0) skY = 1; else skY = -1; } else { if (rozY > 0) skY = 1; else skY = -1; } sX += skX; sY += skY; } else { int skX, skY; if (rozY > 0) skY = 2; else skY = -2; if (rozX == 0) { if ((sX-1) < 0) skX = 1; else skX = -1; } else { if (rozX > 0) skX = 1; else skX = -1; } sX += skX; sY += skY; } } } else { pocetSkoku += pole[sX][sY]; } /* System.out.println(); for(int i=0; i<maxY; i++) { for(int j=0; j<maxX; j++) { System.out.print(pole[j][i]+" "); } System.out.println(); } */ break; } } } }
--- c4.s1253.cteam113.grasshop.java.0.Grasshop.java +++ c4.s1272.cteam113.grasshop.java.0.Grasshop.java @@ -43,7 +43,7 @@ if (ln.length < 6) break; - if (!prvni) System.out.println(); +/* if (!prvni) System.out.println(); prvni = false; - +*/ maxX = Integer.parseInt(ln[0]); maxY = Integer.parseInt(ln[1]); @@ -54,10 +54,10 @@ if ((sX == cX) && (sY == cY)) { - System.out.print("0"); + System.out.println("0"); continue; } if ((maxX < 2) || (maxY < 2)) { - System.out.print("impossible"); + System.out.println("impossible"); continue; } @@ -128,8 +128,8 @@ if (pocetSkoku == Integer.MAX_VALUE) { - System.out.print("impossible"); + System.out.println("impossible"); } else { pocetSkoku += pole[sX][sY]; - System.out.print(pocetSkoku); + System.out.println(pocetSkoku); } /*