Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 990 Bytes

1620.-coordinate-with-maximum-network-quality.md

File metadata and controls

36 lines (29 loc) · 990 Bytes

1620. Coordinate With Maximum Network Quality

class Solution:
    def bestCoordinate(self, towers: List[List[int]], radius: int) -> List[int]:
        
        def singal(q , d):
            return int(q/(1+d))
        
        def distance(q , p):
            return  ((q[0] - p[0])**2 + (q[1] - p[1])**2)**0.5
        
        towers.sort()
        res = dict()
        for i in range(len(towers)):
            ans = 0
            # print('sd')
            for j in range(len(towers)):
                p1 = towers[i][:2]
                p2 = towers[j][:2]
                q_ = towers[j][-1]
                d = distance(p1,p2)
                if d > radius:
                    continue
                # print(q_, d, singal(q_,d))
                ans += singal(q_,d)
            res[tuple(towers[i][:2])] = ans
        
        max_ = max(res.values())
        # print(res,max_)
        for k,v in res.items():
            if v == max_:
                return list(k)