- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find minimum radius such that atleast k point lie inside the circle in C++

Suppose we have some points, and one integer k. We have to find minimum radius of a circle whose center is at (0, 0) to cover k points. So if the points are like (1, 1), (-1, -1), (1, -1), and k = 3, then radius will be 2.

Here we will find the Euclidean distance between each point and (0, 0), then sort the distances and return the kth element after sorting.

## Example

#include<iostream> #include<algorithm> using namespace std; struct point{ int x, y; }; int minRadius(int k, point points[], int n) { int dist[n]; for (int i = 0; i < n; i++) dist[i] = points[i].x * points[i].x + points[i].y * points[i].y; // Sorting the distance sort(dist, dist + n); return dist[k - 1]; } int main() { int k = 3; point points[] = {{1, 1}, {-1, -1}, {1, -1}}; int n = sizeof(points)/sizeof(points[0]); cout << "Minimum radius: " << minRadius(k, points, n) << endl; }

## Output

Minimum radius: 2

- Related Articles
- Find minimum x such that (x % k) * (x / k) == n in C++
- Find if a point lies inside a Circle in C++
- Queries on count of points lie inside a circle in C++
- Place k elements such that minimum distance is maximized in C++
- Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++
- A circle has radius $12 cm$. What is the length of the longest stick that can be placed inside this circle such that the two ends of the stick lie on the circle? Choose the correct option.$( a). 12 cm$$( b). 24 cm$$( c). 18 cm$$( d). 36 cm$
- Find the number of points that have atleast 1 point above, below, left or right of it in C++
- Find smallest number K such that K % p = 0 and q % K = 0 in C++
- Find prime number K in an array such that (A[i] % K) is maximum in C++
- O is the centre of a circle of radius 8 cm. The tangent at a point A on the circle cuts a line through O at B such that $AB = 15 cm$. Find OB.
- Find a point such that sum of the Manhattan distances is minimize in C++
- Maximum value K such that array has at-least K elements that are >= K in C++
- Prove that the tangent at any point of a circle is perpendicular to the radius through the point of contact.
- If the tangent at a point P to a circle with centre O cuts a line through O at Q such that $PQ = 24 cm$ and $OQ = 25 cm$. Find the radius of the circle.
- Find maximum value of x such that n! % (k^x) = 0 in C++

Advertisements