Go to diff to previous submission
import java.io.BufferedReader; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.StringTokenizer; /** * * @author cteam022 */ public class Grasshopper { /** * @param args the command line arguments */ Grasshopper g = new Grasshopper(); while(true){g.uloha();} } int x = x1, y = y1; int i = 0; /* for(i=0; Math.abs(x - x2) > 2 && Math.abs(y - y2)>2; i++){ int dx = x2 - x; int dy = y2 - y; if(Math.abs(dx) >= Math.abs(dy)){ x += Math.signum(dx)*2; y += Math.signum(dy); }else{ x += Math.signum(dx); y += Math.signum(dy)*2; } }*/ boolean[][] visited = new boolean[b][a]; for (int k = 0; k < b; k++) for (int l = 0; l < a; l++) visited[k][l] = false; int p = rekurze(6, x2, y2, a, b, visited, fifo); if(p == -1){ }else{ } } static int rekurze(int pocet, int x2, int y2, int a, int b, boolean[][] visited, LinkedList<Integer[]> fifo){ while (!fifo.isEmpty()) { int x = coords[0]; int y = coords[1]; int dep = coords[2]; if (visited[y][x]) continue; visited[y][x] = true; if (x2 == x && y2 == y) return dep; for(int druhx = -1; druhx < 2; druhx+=2){ for(int druhy = -1; druhy < 2; druhy+=2){ if(x+druhx*2 < a && x+druhx*2>=0 && y+druhy < b && y+druhy >=0){ } if(x+druhx < a && x+druhx>=0 && y+druhy*2 < b && y+druhy*2 >=0){ } } } } return -1; } }
--- c4.s777.cteam022.grasshop.java.0.Grasshopper.java +++ c4.s783.cteam022.grasshop.java.0.Grasshopper.java @@ -42,6 +42,7 @@ int x = x1, y = y1; - int i; + int i = 0; + /* for(i=0; Math.abs(x - x2) > 2 && Math.abs(y - y2)>2; i++){ int dx = x2 - x; @@ -55,5 +56,5 @@ y += Math.signum(dy)*2; } - } + }*/ LinkedList<Integer[]> fifo = new LinkedList<Integer[]>();