Source code for submission s890

Go to diff to previous submission

Grasshop.java

  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Grasshop {
  5.  
  6. public static void main(String[] args) {
  7. int i,z,j,k,i1,i2,j1,j2;
  8. boolean skok = true;
  9.  
  10. int tah[][] = new int[9][2];
  11. tah[8][0]=1; tah[8][1]=2;
  12. tah[1][0]=2; tah[1][1]=1;
  13. tah[2][0]=2; tah[2][1]=-1;
  14. tah[3][0]=1; tah[3][1]=-2;
  15. tah[4][0]=-1; tah[4][1]=-2;
  16. tah[5][0]=-2; tah[5][1]=-1;
  17. tah[6][0]=-2; tah[6][1]=1;
  18. tah[7][0]=-1; tah[7][1]=2;
  19.  
  20. Scanner sc = new Scanner(System.in);
  21. while(sc.hasNext()){
  22. int r = sc.nextInt();
  23. int c = sc.nextInt();
  24. int gr = sc.nextInt();
  25. int gc = sc.nextInt();
  26. int lr = sc.nextInt();
  27. int lc = sc.nextInt();
  28.  
  29. int sach[][]= new int[c+3][r+3];
  30.  
  31. for(i=1;i<=c;i++){
  32. for(j=1;j<=r;j++){
  33. sach[i][j]=-1;
  34. }
  35. }
  36.  
  37. sach[gc][gr]=0;
  38. int krok=1;
  39.  
  40.  
  41.  
  42. while(sach[lc][lr]==-1){
  43. skok = false;
  44. for(i1=1;i1<=c;i1++){
  45. for(i2=1;i2<=r;i2++){
  46. if(sach[i1][i2]==krok-1){
  47.  
  48. for(k=1;k<=8;k++){
  49. j1=i1+tah[k][0];
  50. j2=i2+tah[k][1];
  51.  
  52.  
  53. if((j2>0)&&(j2<r+1)&&(j1>0)&&(j1<c+1)){
  54. if(sach[j1][j2]==-1){
  55. sach[j1][j2]=krok;
  56. skok = true;
  57. }
  58. }
  59.  
  60. }
  61. }
  62. }
  63. }
  64. krok++;
  65.  
  66. if(!skok){break;}
  67.  
  68.  
  69. }
  70.  
  71. if((gc==lc)&&(gr==lr)){
  72. System.out.println("0");
  73. } else {
  74. if(skok==true){System.out.println(sach[lc][lr]);
  75. } else {
  76. System.out.println("impossible");
  77. }
  78. }
  79. }
  80.  
  81.  
  82. }
  83.  
  84. }
  85.  

Diff to submission s855

Grasshop.java

--- 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");    
           }