力扣 1620. 网络信号最好的坐标

解法:暴力

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def bestCoordinate(towers, radius):
# 暴力枚举
dp = [[0] * 110 for _ in range(110)]
x, y, power = 0, 0, 0
for dx, dy, dpo in towers:
for i in range(max(0, dx - radius), dx + radius + 1):
for j in range(max(0, dy - radius), dy + radius + 1):
d = math.sqrt((dx - i) ** 2 + (dy - j) ** 2)
if d > radius:
continue
cur = math.floor(dpo / (1 + d))
dp[i][j] += cur
if dp[i][j] > power:
x, y = i, j
power = dp[i][j]
elif dp[i][j] == power and (i < x or (i == x and j < y)):
x, y = i, j
return [x, y]
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信