fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Codechef
  7. {
  8. static int n,m,flag;
  9. static int arr[][];
  10.  
  11. public static void main(String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. System.out.println("ee");
  15. int t = Integer.parseInt(br.readLine());
  16. for(;t!=0;t--)
  17. {
  18. int sx,sy,dx,dy;
  19. StringTokenizer st = new StringTokenizer(br.readLine());
  20. n=Integer.parseInt(st.nextToken());
  21. m=Integer.parseInt(st.nextToken());
  22.  
  23. st = new StringTokenizer(br.readLine());
  24. sx=Integer.parseInt(st.nextToken());
  25. sy=Integer.parseInt(st.nextToken());
  26.  
  27. st = new StringTokenizer(br.readLine());
  28. dx=Integer.parseInt(st.nextToken());
  29. dy=Integer.parseInt(st.nextToken());
  30.  
  31. arr= new int[1001][1001];
  32. flag=0;
  33. cal(sx,sy,dx,dy);
  34. }
  35. }
  36. public static boolean chk(int x,int y)
  37. {
  38. if(x>=1 && x<=n && y>=1 && y<=m)
  39. return true;
  40.  
  41. return false;
  42. }
  43. public static void print (int arr[][],int cx,int cy)
  44. {
  45. int i,j;
  46. for(i=1;i<=n;i++)
  47. {
  48. for(j=1;j<=m;j++)
  49. System.out.print(arr[i][j]);
  50.  
  51. System.out.println();
  52. }
  53. System.out.print(cx+" "+cy);
  54. System.out.println();
  55. }
  56.  
  57. public static void cal(int cx,int cy,int dx,int dy)
  58. {
  59. if(flag==0)
  60. {
  61.  
  62. arr[cx][cy]=1;
  63. if(cx==dx && cy==dy)
  64. {
  65. flag=1;
  66. if(chk(cx,cy+1)==true && arr[cx][cy+1]==0)
  67. {System.out.println("Right");return;}
  68.  
  69. if(chk(cx,cy-1)==true && arr[cx][cy-1]==0)
  70. {System.out.println("Left");return;}
  71.  
  72. if(chk(cx-1,cy)==true && arr[cx-1][cy]==0)
  73. {System.out.println("Front");return;}
  74.  
  75. if(chk(cx+1,cy)==true && arr[cx+1][cy]==0)
  76. {System.out.println("Back");return;}
  77.  
  78. System.out.println("Over");return;
  79.  
  80. }
  81. else
  82. {
  83. if(chk(cx,cy+1)==true && arr[cx][cy+1]==0)
  84. {
  85. cal(cx,cy+1,dx,dy);
  86. }
  87. if(chk(cx,cy-1)==true && arr[cx][cy-1]==0)
  88. {
  89. cal(cx,cy-1,dx,dy);
  90. }
  91. if(chk(cx-1,cy)==true && arr[cx-1][cy]==0)
  92. {
  93. cal(cx-1,cy,dx,dy);
  94. }
  95. if(chk(cx+1,cy)==true && arr[cx+1][cy]==0)
  96. {
  97. cal(cx+1,cy,dx,dy);
  98. }
  99. }
  100. }
  101. }
  102. }
Success #stdin #stdout 0.04s 4386816KB
stdin
2
3 3
1 1
3 3
2 3
1 3
2 2
stdout
ee
Over
Right