⭐ 雷达设备
输入样例
3 2
1 2
-3 1
2 1
输出样例
2
⭐ 思路
将处理雷达能覆盖的岛屿圆,转变成岛屿能接收到信号的雷达区间
🥚 一个小岛一个区间,要求每个区间都要有雷达
🥚 勾股定理算出所有的区间 sqrt(d^2 - y^2)= r : [x-r, x+r] 就是该岛屿能接收信号的区间
🥚 所有右端点排序,每次选右端点装置雷达 ,将能覆盖的区间全部去掉
import java.util.*;
public class Main
{
static int N = 1010;
static double INF = 1e10;
static double eps = 1e-6;// 处理精度差
static class Pair
{
double l;
double r;
public Pair(double l, double r)
{
super();
this.l = l;
this.r = r;
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int d = sc.nextInt();
Pair[] a = new Pair[n];
for (int i = 0; i < n; i++)
{
int x = sc.nextInt();
int y = sc.nextInt();
if (y > d)
{
System.out.println(-1);
System.exit(0);
}
double t = Math.sqrt((d * d - y * y));
a[i] = new Pair(x - t, x + t);
}
Arrays.sort(a, (o1, o2) -> Double.compare(o1.r, o2.r));
int res = 0;
double last = -INF;
for (int i = 0; i < n; i++)
{
if (a[i].l > last + eps)
{
res++;
last = a[i].r;
}
}
System.out.println(res);
}
}