内卷地狱

1828. Statistics the number of a circle mid -point One question daily

Edit Me

topic:

1828. Statistics the number of a circle mid -point

Thought:

Today's question is very simple,I wonder if it is against yesterday's question bidding。 AskqueriesThere are a few in the circlepointsPoints in an array。 To be honest, I was scared,I think this question is the question of the picture again。不过仔细读题了后发现只是一道简单的math题, We can use European -style distance to solve(Time complexity isOn^2,I thought I had a better solution,At first glance everyone is like this())

The formula of the European -style distance is as follows:

(x1x2)2+(y1y2)2\sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}

We look at the code for specific operations:

Code

class Solution:
    def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
        # Seek to solve whether the European -style distance from the center is less than r
        ans = [0] * len(queries)
        flag = 0
        for x, y, r in queries:
            for i, j in points:
                if ((x - i) ** 2 + (y - j) ** 2) ** (1 / 2) <= r:
                    ans[flag] += 1
            flag += 1
        return ans

Take a look at someone who can't understandpythonCode:

class Solution:
    def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
        points = sorted(points)

        res = [0 for _ in range(len(queries))]

        for i, (u, v, r) in enumerate(queries):
            left, right = u - r, u + r

            idx1 = bisect_left(points, [left, -inf])
            idx2 = bisect_right(points, [right, inf])

            for x, y in points[idx1: idx2 + 1]:
                if (v - r <= y <= v + r and
                    (x - u) * (x - u) + (y - v) * (y - v) <= r * r):

                    res[i] += 1

        return res

贡献者


这篇文章有帮助吗?

最近更新

Involution Hell© 2026 byCommunityunderCC BY-NC-SA 4.0CCBYNCSA