AcWing 112. 雷达设备
原题链接
中等
作者:
XianZS.com
,
2024-10-03 10:37:38
,
所有人可见
,
阅读 1
Python
排序+小根堆
import heapq
n,d=map(int,input().split())
def main() -> int:
ins=list()
for _ in range(n):
x,y=map(int,input().split())
if y>d:
return -1
number=pow(d*d-y*y,1/2)
a=x-number
b=x+number
ins.append((a,b))
ins.sort(reverse=False,key=lambda x:x[1])
# print(ins)
ans=list()
heapq.heapify(ans)
heapq.heappush(ans,ins[0])
res=1
for x in range(1,n):
if ans[0][1]<ins[x][0]:
heapq.heappop(ans)
heapq.heappush(ans,ins[x])
res+=1
return res
print(main())