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]

本文介绍了一种通过遍历网格来寻找网络信号质量最佳坐标的算法实现。该方法适用于LeetCode上的网络信号最好坐标问题,通过对每个可能的坐标位置进行强度评估,找到满足条件的最佳坐标。
873

被折叠的 条评论
为什么被折叠?



