Source code for submission s949

Go to diff to previous submission

Kon.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package kon;
  6.  
  7. import java.awt.Point;
  8. import java.util.LinkedList;
  9. import java.util.Queue;
  10. import java.util.Scanner;
  11.  
  12. /**
  13.  *
  14.  * @author student
  15.  */
  16. public class Kon {
  17.  
  18. private static boolean[][] map;
  19. private static int sx, sy, rx, ry, ex, ey;
  20. private static Queue<Point> st;
  21. private static int sol;
  22.  
  23. public static void main(String[] args) {
  24. Scanner sc = new Scanner(System.in);
  25.  
  26. int[][] podm = {{1,2},{2,1},{2, -1},{1,-2}, {-1,-2}, {-2,-1},{-2,1},{-1,2}};
  27.  
  28. while(sc.hasNextInt())
  29. {
  30. rx = sc.nextInt();
  31. ry = sc.nextInt();
  32. sx = sc.nextInt();
  33. sy = sc.nextInt();
  34. ex = sc.nextInt();
  35. ey = sc.nextInt();
  36.  
  37. st = new LinkedList<Point>();
  38.  
  39. map = new boolean[rx+1][ry+1];
  40. sol = 1;
  41.  
  42. map[sx][sy] = true;
  43. st.offer(new Point(sx, sy));
  44. st.offer(null);
  45.  
  46. if(sx == ex && sy == ey)
  47. {
  48. System.out.println(0);
  49. }
  50. else
  51. {
  52. while(true)
  53. {
  54. if(st.size() == 1)
  55. {
  56. System.out.println("impossible");
  57. break;
  58. }
  59.  
  60. Point p = st.remove();
  61.  
  62. if(p == null)
  63. {
  64. st.add(null);
  65. sol++;
  66. continue;
  67. }
  68.  
  69. int x, y;
  70. boolean mimo = false;
  71. for(int j=0; j<8; j++)
  72. {
  73. x = p.x + podm[j][0];
  74. y = p.y + podm[j][1];
  75.  
  76. if(0 < x && x <= rx && 0 < y && y <= ry)
  77. {
  78. mimo = solve(x, y);
  79. if(mimo) break;
  80. }
  81. }
  82.  
  83. if(mimo) break;
  84. }
  85. }
  86. }
  87. }
  88.  
  89. private static boolean solve(int x, int y)
  90. {
  91. if(!map[x][y])
  92. {
  93. if(x == ex && y == ey)
  94. {
  95. System.out.println(sol);
  96. return true;
  97. }
  98. else
  99. {
  100. st.offer(new Point(x, y));
  101. map[x][y] = true;
  102. }
  103. }
  104.  
  105. return false;
  106. }
  107. }
  108.  

Diff to submission s946

Kon.java

--- c4.s946.cteam122.grasshop.java.0.Kon.java
+++ c4.s949.cteam122.grasshop.java.0.Kon.java
@@ -44,5 +44,5 @@
             st.offer(null);
             
-            if(rx ==1 && ry ==1 &&  sx == 1 && sy ==1 && ex ==1 && ey == 1)
+            if(sx == ex && sy == ey)
             {
                 System.out.println(0);