1620. Coordinate With Maximum Network Quality Medium
1/**
2 * [1620] Coordinate With Maximum Network Quality
3 *
4 * You are given an array of network towers towers, where towers[i] = [xi, yi, qi] denotes the i^th network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane, and the distance between the two coordinates is the Euclidean distance.
5 * You are also given an integer radius where a tower is reachable if the distance is less than or equal to radius. Outside that distance, the signal becomes garbled, and the tower is not reachable.
6 * The signal quality of the i^th tower at a coordinate (x, y) is calculated with the formula ⌊qi / (1 + d)⌋, where d is 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.
7 * 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.
8 * Note:
9 *
10 * A coordinate (x1, y1) is lexicographically smaller than (x2, y2) if either:
11 *
12 * x1 < x2, or
13 * x1 == x2 and y1 < y2.
14 *
15 *
16 * ⌊val⌋ is the greatest integer less than or equal to val (the floor function).
17 *
18 *
19 * Example 1:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2020/09/22/untitled-diagram.png" style="width: 176px; height: 176px;" />
21 * Input: towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2
22 * Output: [2,1]
23 * Explanation: At coordinate (2, 1) the total quality is 13.
24 * - Quality of 7 from (2, 1) results in ⌊7 / (1 + sqrt(0)⌋ = ⌊7⌋ = 7
25 * - Quality of 5 from (1, 2) results in ⌊5 / (1 + sqrt(2)⌋ = ⌊2.07⌋ = 2
26 * - Quality of 9 from (3, 1) results in ⌊9 / (1 + sqrt(1)⌋ = ⌊4.5⌋ = 4
27 * No other coordinate has a higher network quality.
28 * Example 2:
29 *
30 * Input: towers = [[23,11,21]], radius = 9
31 * Output: [23,11]
32 * Explanation: Since there is only one tower, the network quality is highest right at the tower's location.
33 *
34 * Example 3:
35 *
36 * Input: towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2
37 * Output: [1,2]
38 * Explanation: Coordinate (1, 2) has the highest network quality.
39 *
40 *
41 * Constraints:
42 *
43 * 1 <= towers.length <= 50
44 * towers[i].length == 3
45 * 0 <= xi, yi, qi <= 50
46 * 1 <= radius <= 50
47 *
48 */
49pub struct Solution {}
50
51// problem: https://leetcode.com/problems/coordinate-with-maximum-network-quality/
52// discuss: https://leetcode.com/problems/coordinate-with-maximum-network-quality/discuss/?currentPage=1&orderBy=most_votes&query=
53
54// submission codes start here
55
56impl Solution {
57 pub fn best_coordinate(towers: Vec<Vec<i32>>, radius: i32) -> Vec<i32> {
58 vec![]
59 }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_1620() {
70 }
71}
72
Back
© 2025 bowen.ge All Rights Reserved.