main.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <limits>
  5. using namespace std;
  6. const double eps = 1e-6;
  7. int n, d, id = 0;
  8. struct Island {
  9. double rs;
  10. double re;
  11. void set(int x, int y) {
  12. double dx = sqrt(double(d) * d - double(y) * y);
  13. rs = x - dx;
  14. re = x + dx;
  15. }
  16. bool operator<(const Island &that) { return this->rs < that.rs; }
  17. };
  18. int main() {
  19. Island is[1000];
  20. while (scanf("%d %d", &n, &d) != EOF && (n != 0 || d != 0)) {
  21. int x, y, cnt = 0;
  22. for (int i = 0; i < n; i++) {
  23. scanf("%d %d", &x, &y);
  24. if (d < fabs(y)) { // !!!y maybe negative
  25. cnt = -1;
  26. continue;
  27. }
  28. is[i].set(x, y);
  29. }
  30. if (cnt == 0) {
  31. sort(is, is + n);
  32. // Avoid overflow, use -max instead of min
  33. double end = -numeric_limits<double>::max();
  34. for (int i = 0; i < n; i++) {
  35. if (is[i].rs - end > eps) {
  36. cnt++;
  37. end = is[i].re;
  38. } else if (end - is[i].re > eps) {
  39. end = is[i].re;
  40. }
  41. }
  42. }
  43. printf("Case %d: %d\n", ++id, cnt);
  44. }
  45. return 0;
  46. }