#P3091. Cow Visibility
Cow Visibility
Cow Visibility
Farmer John has N cows located at distinct points in his two‐dimensional pasture. In the middle of the pasture stands a large circular grain silo centered at the origin with radius (R). No cow lies on or inside the circle and no two cows lie on a line that is tangent to the silo. Two cows can see each other via a direct line‐of–sight if and only if the line segment connecting them does not intersect the circle. It can be shown that this condition is equivalent to
[ \min(|\theta_i - \theta_j|,;2\pi - |\theta_i - \theta_j|) < \arccos\Big(\frac{R}{r_i}\Big) + \arccos\Big(\frac{R}{r_j}\Big), ]
where for a cow at ((x,y)) we define (r=\sqrt{x^2+y^2}) and (\theta) is its polar angle (in radians, within ([0,2\pi))).
Your task is to count the number of pairs of cows that can see each other.
Constraints
- \(1 \le N \le 50\,000\)
- \(1 \le R \le 10^6\)
- \(|x|,|y| \le 10^6\); all cows lie strictly outside the circle \(x^2+y^2 = R^2\).
Note: It is guaranteed that no connecting line between any two cows is tangent to the circle.
inputFormat
The first line contains two integers \(N\) and \(R\). Each of the next \(N\) lines contains two integers \(x\) and \(y\) that denote the coordinates of a cow.
For example:
3 1 2 0 0 2 -2 2
outputFormat
Output a single integer, the number of pairs of cows that can see each other.
For the sample input above, the correct output is 2.
sample
3 1
2 0
0 2
-2 2
2
</p>