Day 35
Date: November 1, 2022 4:34 PM
LinkedIn: https://leetcode.cn/problems/coordinate-with-maximum-network-quality/description/
Title: 网络信号最好的坐标
暴力直接求
class Solution:
def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]:
max_pw = 0 # 最大强度
x = 0 # 最大坐标
y = 0
for x1 in range(51):
for y1 in range(51):
pw = 0 # 初始化
for x2, y2, v2 in towers:
d = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
if d <= radius:
pw += floor(v2 / (1 + d)) # 根据样例公式下取整
if max_pw < pw:
max_pw = pw
x = x1
y = y1
return [x, y]