원의 중심 좌표와 반지름의 길이가 주어지고, N개의 점이 입력으로 주어진다.
해당 원 안에 포함되거나 걸치는 점의 개수를 각각의 원에 대해서 반환하는 문제다.
from typing import *
class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
answer = []
for query in queries:
cx, cy, length = query
temp = 0
for point in points:
x, y = point
if (cx - x) * (cx - x) + (cy - y) * (cy - y) <= length * length:
temp += 1
answer.append(temp)
return answer
문제는 간단한데, 원의 중심과 주어진 점의 거리가 원의 반지름보다 같거나 작은 경우에 카운트를 올려주면 된다.
하지만 이 문제는 굉장히 재밌는 문제인데 관련한 내용은 아래 포스트 참고.
'Algorithm' 카테고리의 다른 글
1551. Minimum Operations to Make Array Equal (0) | 2021.08.08 |
---|---|
1329. Sort the Matrix Diagonally (0) | 2021.08.07 |
1315. Sum of Nodes with Even-Valued Grandparent (0) | 2021.08.05 |
1832. Check if the Sentence Is Pangram (0) | 2021.08.04 |
938. Range Sum of BST (0) | 2021.08.03 |