fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Dot
  6. {
  7. public double x, y;
  8.  
  9. public Dot() {}
  10.  
  11. public Dot(double x, double y)
  12. {
  13. this.x = x;
  14. this.y = y;
  15. }
  16. }
  17.  
  18. public class Main
  19. {
  20. public static double euclidianDistanceToZero(Dot a)
  21. {
  22. return Math.sqrt(a.x*a.x+a.y*a.y);
  23. }
  24.  
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. Scanner in = new Scanner(System.in);
  28. PrintWriter out = new PrintWriter(System.out);
  29.  
  30. int n_dot = in.nextInt();
  31. int n_circ = in.nextInt();
  32.  
  33. Vector <Dot> dots = new Vector<Dot>();
  34.  
  35. for(int i = 0; i < n_dot; ++i)
  36. {
  37. Dot a = new Dot(in.nextDouble(), in.nextDouble());
  38. if (a.y > 0)
  39. dots.addElement(a);
  40. }
  41.  
  42. double rads[] = new double[n_circ];
  43. int amounts[] = new int[n_circ];
  44.  
  45. for(int i = 0; i < n_circ; ++i)
  46. {
  47. rads[i] = in.nextDouble();
  48. amounts[i] = 0;
  49. }
  50.  
  51. if (n_circ == 1)
  52. {
  53. for(int i = 0; i < dots.size(); ++i)
  54. if (euclidianDistanceToZero(dots.elementAt(i)) < rads[0])
  55. ++amounts[0];
  56. }
  57. else
  58. for(int i = 0; i < dots.size(); ++i)
  59. {
  60. int j = n_circ;
  61. double r = euclidianDistanceToZero(dots.elementAt(i));
  62.  
  63. if (r < rads[n_circ-1]) // if dot belongs to one of the semicircles
  64. {
  65. if (r < rads[0]) // if dot belongs to the first semicircle
  66. j = 0;
  67. else if (rads[n_circ-2] <= r) // if dot belongs to the last semicircle
  68. j = n_circ-1;
  69. else // binary search of the smallest semicircle, which includes dot
  70. {
  71. int prev_l = 0, prev_r = n_circ, k;
  72.  
  73. while(j == n_circ)
  74. {
  75. k = (prev_l+prev_r)/2;
  76.  
  77. if (rads[k-1] <= r && r < rads[k])
  78. j = k;
  79. else if (r >= rads[k])
  80. prev_l = (prev_l+k)/2;
  81. else //if (r < rads[k-1])
  82. prev_r = (prev_r+k)/2;
  83. }
  84. }
  85.  
  86. ++amounts[j]; //increasing amount of dots, which belong to [j, n_circ-1] circles.
  87. }
  88. }
  89.  
  90. for(int accumulated_amount = 0, i = 0; i < n_circ; ++i)
  91. {
  92. accumulated_amount += amounts[i];
  93. amounts[i] = accumulated_amount;
  94. }
  95.  
  96. for(int i = 0; i < n_circ; ++i)
  97. out.println(String.valueOf(amounts[i]));
  98. out.flush();
  99. }
  100. }
Success #stdin #stdout 0.07s 842752KB
stdin
20 11
14 4
5 -4
4 90
2 4.91
8 9.0
8.3 4.111 
20 49.0
0 301.419
8.01 34.5
2.1 -49.1
0.01 0.03
56 1.91
4.04918 34.49294
-1.85892 5.01674
51 214
14.94 44.09
41.4 -154
-581.49 495
14.39 -81.682
77 194.4
0.3
20.82
50.9
51
65.845
90.37
109.58
170.83
217
301.58901
314
stdout
1
6
9
9
11
12
12
12
13
15
15