LEETCODE | PYTHON | 1828 | 统计一个圆中点的数目
1. 题目
(1)给你一个数组 points ,其中 points[i] = [xi, yi] ,表示第 i 个点在二维平面上的坐标。多个点可能会有 相同 的坐标。
(2)同时给你一个数组 queries ,其中 queries[j] = [xj, yj, rj] ,表示一个圆心在 (xj, yj) 且半径为 rj 的圆。
(3)对于每一个查询 queries[j] ,计算在第 j 个圆 内 点的数目。如果一个点在圆的 边界上 ,我们同样认为它在圆 内 。
(4)请你返回一个数组 answer ,其中 answer[j]是第 j 个查询的答案。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/queries-on-number-of-points-inside-a-circle
2. 思路简析
**STEP 1:**遍历每个圆进行数目计算
**STEP 2:**遍历每个点确认点与圆心的距离是否大于半径
3. 代码
class Solution(object):
def countPoints(self, points, queries):
"""
:type points: List[List[int]]
:type queries: List[List[int]]
:rtype: List[int]
"""
result = []
for j in range(0,len(queries)):
tmp = 0
o_x = queries[j][0]
o_y = queries[j][1]
o_r = queries[j][2]
for i in range(0,len(points)):
x = points[i][0]
y = points[i][1]
if pow(x - o_x,2) + pow(y - o_y,2) <= pow(o_r,2):
tmp = tmp+1
result.append(tmp)
return result