You are given the location of N devices on a coordinate plane and an integer K. Location of
the device is donated by . A modem is located at . The range of modem is circular. All the devices within the range of the modem will connect to the modem. You have to find the minimum integral radius of the circular range of the modem such that at-least K devices will connect to the modem.
Example:
Input: n = 3, k = 3, x = [1,-1,1], y = [1,-1,-1]
Output: 2
Approach
C++
#include <bits/stdc++.h>using namespace std;long long kDevices(long long n, long long k,long long x[], long long y[]){vector<long long> v;for (long long i = 0; i < n; i++){long long p = (x[i] * x[i] + y[i] * y[i]);double q = sqrt(p);q = ceil(q);v.push_back(q);}sort(v.begin(), v.end());return v[k - 1];}int main(){long long n = 3, k = 3;long long x[n] = {1, -1, 1};long long y[n] = {1, -1, -1};cout << kDevices(n, k, x, y) << "\n";return 0;}
No comments:
Post a Comment