Go to diff to previous submission
import java.util.Scanner; public class Grasshop { int i,z,j,k,i1,i2,j1,j2; boolean skok = true; int tah[][] = new int[9][2]; tah[8][0]=1; tah[8][1]=2; tah[1][0]=2; tah[1][1]=1; tah[2][0]=2; tah[2][1]=-1; tah[3][0]=1; tah[3][1]=-2; tah[4][0]=-1; tah[4][1]=-2; tah[5][0]=-2; tah[5][1]=-1; tah[6][0]=-2; tah[6][1]=1; tah[7][0]=-1; tah[7][1]=2; while(sc.hasNext()){ int r = sc.nextInt(); int c = sc.nextInt(); int gr = sc.nextInt(); int gc = sc.nextInt(); int lr = sc.nextInt(); int lc = sc.nextInt(); int sach[][]= new int[c+3][r+3]; for(i=1;i<=c;i++){ for(j=1;j<=r;j++){ sach[i][j]=-1; } } sach[gc][gr]=0; int krok=1; while(sach[lc][lr]==-1){ skok = false; for(i1=1;i1<=c;i1++){ for(i2=1;i2<=r;i2++){ if(sach[i1][i2]==krok-1){ for(k=1;k<=8;k++){ j1=i1+tah[k][0]; j2=i2+tah[k][1]; if((j2>0)&&(j2<r+1)&&(j1>0)&&(j1<c+1)){ if(sach[j1][j2]==-1){ sach[j1][j2]=krok; skok = true; } } } } } } krok++; if(!skok){break;} } if((gc==lc)&&(gr==lr)){ } else { } else { } } } } }
--- c4.s855.cteam060.grasshop.java.0.Grasshop.java +++ c4.s890.cteam060.grasshop.java.0.Grasshop.java @@ -6,5 +6,6 @@ public static void main(String[] args) { int i,z,j,k,i1,i2,j1,j2; - boolean skok = false; + boolean skok = true; + int tah[][] = new int[9][2]; tah[8][0]=1; tah[8][1]=2; @@ -38,6 +39,5 @@ - - if((gr!=lr)&&(gc!=lc)) + while(sach[lc][lr]==-1){ skok = false; @@ -63,13 +63,15 @@ } krok++; + if(!skok){break;} } + if((gc==lc)&&(gr==lr)){ System.out.println("0"); } else { - if(skok==true){System.out.println(sach[lc][lr]);} - else { + if(skok==true){System.out.println(sach[lc][lr]); + } else { System.out.println("impossible"); }