今天是一道中等题。。。但是题目有点奇怪
乍一看这题好难啊,暴力解法肯定不行。。。
然后想很久没想出来什么简便方法,看了官方题解,就tm是暴力法
整个无语了!!!!!
算法思想:遍历没一个可能的点,求其信号值,即可得出最大信号值的坐标点!
- class Solution:
- def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]:
- x_max = max(t[0] for t in towers)
- y_max = max(t[1] for t in towers)
- cx = cy = max_quality = 0
- for x in range(x_max + 1):
- for y in range(y_max + 1):
- quality = 0
- for tx, ty, q in towers:
- d = (x - tx) ** 2 + (y - ty) ** 2
- if d <= radius ** 2:
- quality += int(q / (1 + d ** 0.5))
- if quality > max_quality:
- cx, cy, max_quality = x, y, quality
- return [cx, cy]
完成!