【LeetCode】每日一题——1610. 可见点的最大数目

目录

 题目:

​ 思路:

 代码:

分析:


 题目:

力扣

 思路:

我想先算出每个点和定点和x轴的角度

然后这些角度排序

然后将最小的加90度看有 这些角度有多少在这个区间

依次这样下去

然后去最大的

这个90度 (就是那个angle)
 

 代码:

class Solution:
    def visiblePoints(self, points: List[List[int]], angle: int, location: List[int]) -> int:
        samecnt = 0
        polardegress = []
        for p in points:
            if p == location:
                samecnt += 1
            else:
                polardegress.append(atan2(p[1]-location[1],p[0]-location[0]))
        polardegress.sort()

        n = len(polardegress)
        polardegress += [deg +2*pi for deg in polardegress]
        drgree = angle * pi /180
        maxcnt = max((bisect_right(polardegress,polardegress[i]+drgree) -i for i in range(n)),default=0)
        return maxcnt+samecnt

分析:

关于bisect

Python中的bisect_整洁的松鼠l的博客-CSDN博客

猜你喜欢

转载自blog.csdn.net/qq_62932195/article/details/121982593