1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 1010; 4 const double eps = 1e-6, INF = 1e10; 5 //eps用于精度判断 6 typedef pair<double, double> pdd; 7 pdd segs[N]; 8 int main() { 9 int n, r; 10 cin >> n >> r; 11 for (int i = 0; i < n; i++) { 12 int x, y; 13 cin >> x >> y; 14 if (y > r) { 15 cout << -1 << endl; 16 return 0; 17 } 18 double len = sqrt(r * r - y * y); 19 segs[i] = {x + len, x - len}; 20 //需要按照右端点从小到大排序 21 //所以first和second交换一下 22 //second是起点,first是终点 23 } 24 sort(segs, segs + n); 25 int res = 0; 26 double last = -INF; 27 //last是上一个雷达的位置,初始化为负无穷 28 for (int i = 0; i < n; i++) { //扫描一遍 29 if (segs[i].second > last + eps) { //如果当前起点,大于上一个终点 30 res++; 31 last = segs[i].first; 32 } 33 } 34 cout << res << endl; 35 return 0; 36 }