Class Solution
- java.lang.Object
-
- g1601_1700.s1620_coordinate_with_maximum_network_quality.Solution
-
public class Solution extends Object
1620 - Coordinate With Maximum Network Quality.Medium
You are given an array of network towers
towers, wheretowers[i] = [xi, yi, qi]denotes theithnetwork tower with location(xi, yi)and quality factorqi. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance.You are also given an integer
radiuswhere a tower is reachable if the distance is less than or equal toradius. Outside that distance, the signal becomes garbled, and the tower is not reachable.The signal quality of the
ithtower at a coordinate(x, y)is calculated with the formula\u230aqi / (1 + d)\u230b, wheredis the distance between the tower and the coordinate. The network quality at a coordinate is the sum of the signal qualities from all the reachable towers.Return the array
[cx, cy]representing the integral coordinate(cx, cy)where the network quality is maximum. If there are multiple coordinates with the same network quality , return the lexicographically minimum non-negative coordinate.Note:
- A coordinate
(x1, y1)is lexicographically smaller than(x2, y2)if either:x1 < x2, orx1 == x2andy1 < y2.
\u230aval\u230bis the greatest integer less than or equal toval(the floor function).
Example 1:

Input: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2
Output: [2,1]
Explanation: At coordinate (2, 1) the total quality is 13.
-
Quality of 7 from (2, 1) results in \u230a7 / (1 + sqrt(0)\u230b = \u230a7\u230b = 7
-
Quality of 5 from (1, 2) results in \u230a5 / (1 + sqrt(2)\u230b = \u230a2.07\u230b = 2
-
Quality of 9 from (3, 1) results in \u230a9 / (1 + sqrt(1)\u230b = \u230a4.5\u230b = 4
No other coordinate has a higher network quality.
Example 2:
Input: towers = [[23,11,21]], radius = 9
Output: [23,11]
Explanation: Since there is only one tower, the network quality is highest right at the tower’s location.
Example 3:
Input: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2
Output: [1,2]
Explanation: Coordinate (1, 2) has the highest network quality.
Constraints:
1 <= towers.length <= 50towers[i].length == 30 <= xi, yi, qi <= 501 <= radius <= 50
- A coordinate
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]bestCoordinate(int[][] towers, int radius)
-