avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

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

  2024-01-01        
字数统计: 283字   |   阅读时长: 1min

topic:

2023-01-25.png
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:

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

We look at the code for specific operations:

Code

1
2
3
4
5
6
7
8
9
10
11
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
  • Python
  • answer
  • math

扫一扫,分享到微信

微信分享二维码
1825. Seek out MK average value
1819.Different numbers in the sequence
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号