![]() |
VOOZH | about |
Given two pairs (X, Y), (P, Q) and R the coordinate of the center of semi-circle, coordinate of the intersection of semicircle and diameter of the semicircle and, the radius of the semicircle, and an array arr[] of dimension N*2 consisting of the coordinates of few points, the task is to find the number of points from the array that lies inside or on the
semicircle.
Note: The semicircle above the diameter is considered.
Examples:
Input: X = 0, Y = 0, R = 5, P = 5, Q = 0, arr[][] = { {2, 3}, {5, 6}, {-1, 4}, {5, 5} }
👁 Image
Output: 2
Explanation: The points {2, 3} and {-1, 4} are inside the semi-circle.
Input: X = 2, Y = 3, R = 10, P = 12, Q = 3, arr[][] = { {-7, -5}, {0, 6}, {11, 4} }
Output: 2
Approach: The given problem can be solved based on the following observations:
- The points that lies on or inside the semicircle must be above or on the diameter of semicircle and the distance between center and that point should be ? R.
- Suppose is the equation of diameter.
The point (R, S) lies above the line if
- A point (R, S) lies above the line formed by joining points (X, Y) and (P, Q) if
Follow the steps below to solve the problem:
Below is the implementation of the above approach:
2
Time Complexity: O(N)
Auxiliary Space: O(1)