Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class P4 {
  5.  
  6. public static class Pair {
  7. long x, y;
  8.  
  9. public Pair(long x, long y) {
  10. this.x = x;
  11. this.y = y;
  12. }
  13.  
  14. }
  15.  
  16. public static void main(String[] args) throws IOException {
  17. // br = new BufferedReader(new InputStreamReader(System.in));
  18. br = new BufferedReader(new FileReader("DATA41.txt"));
  19. // br = new BufferedReader(new FileReader("DATA42.txt"));
  20. long dp[] = new long[50]; dp[0] = dp[1] = 1;
  21. Pair start = new Pair(1, -1); Pair [] coords = new Pair[50]; coords[0] = start;
  22. for(int i = 2; i<=49; i++) dp[i] = dp[i-1]+dp[i-2];
  23. for(int i = 1; i<=49; i++) {
  24. long X = coords[i-1].x;
  25. long Y = coords[i-1].y;
  26. if(i%4 == 1) {
  27. X = X-dp[i]-dp[i-1];
  28. }
  29. if(i%4 == 2) {
  30. Y = Y+dp[i]+dp[i-1];
  31. }
  32. if(i%4 == 3) {
  33. X = X+dp[i]+dp[i-1];
  34. }
  35. if(i%4 == 0) {
  36. Y = Y-dp[i]-dp[i-1];
  37. }
  38. coords[i] = new Pair(X, Y);
  39. }
  40.  
  41. // for(int i = 0; i<50; i++) System.out.println(coords[i].x + " " + coords[i].y);
  42. for(int testcasenum = 0; testcasenum < 10; testcasenum++) {
  43. long X = readLong(), Y = readLong();
  44. for(int i = 0; i<50; i++) {
  45. // System.out.println(i);
  46. if(i%4 == 0) {
  47. if(X<=coords[i].x && X>=coords[i].x-dp[i] && Y>=coords[i].y && Y<=coords[i].y+dp[i]) {
  48. System.out.println(i+1); break;
  49. }
  50. }
  51. if(i%4 == 1) {
  52. if(X<=coords[i].x+dp[i] && X>=coords[i].x && Y>=coords[i].y && Y<=coords[i].y+dp[i]) {
  53. System.out.println(i+1); break;
  54. }
  55. }
  56. if(i%4 == 2) {
  57. if(X<=coords[i].x+dp[i] && X>=coords[i].x && Y>=coords[i].y-dp[i] && Y<=coords[i].y) {
  58. System.out.println(i+1); break;
  59. }
  60. }
  61. if(i%4 == 3) {
  62. if(X<=coords[i].x && X>=coords[i].x-dp[i] && Y>=coords[i].y-dp[i] && Y<=coords[i].y+dp[i]) {
  63. System.out.println(i+1); break;
  64. }
  65. }
  66. }
  67. }
  68. flush();
  69. exit();
  70. }
  71.  
  72. static BufferedReader br;
  73. static StringTokenizer st;
  74. static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  75.  
  76. static String read() throws IOException {
  77. while (st == null || !st.hasMoreTokens())
  78. st = new StringTokenizer(br.readLine().trim());
  79. return st.nextToken();
  80. }
  81.  
  82. static long readLong() throws IOException {
  83. return Long.parseLong(read());
  84. }
  85.  
  86. static int readInt() throws IOException {
  87. return Integer.parseInt(read());
  88. }
  89.  
  90. static double readDouble() throws IOException {
  91. return Double.parseDouble(read());
  92. }
  93.  
  94. static char readCharacter() throws IOException {
  95. return read().charAt(0);
  96. }
  97.  
  98. static String readLine() throws IOException {
  99. return br.readLine().trim();
  100. }
  101.  
  102. static void println() throws IOException {
  103. pr.println();
  104. }
  105.  
  106. static void println(Object o) throws IOException {
  107. pr.println(o);
  108. }
  109.  
  110. static void print(Object o) throws IOException {
  111. pr.print(o);
  112. }
  113.  
  114. static void flush() throws IOException {
  115. pr.flush();
  116. }
  117.  
  118. static void exit() throws IOException {
  119. br.close();
  120. pr.close();
  121. System.exit(0);
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement