Language: C++

#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>


#define EPSILON 1e-9


#define ALL(x) (x).begin(), (x).end()


class point_t;


class vector_t {
public:
  double x;
  double y;
  double z;

public:
  vector_t(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {};

  vector_t(const point_t& p);

public:
  vector_t operator-() const {
    return vector_t(-x, -y, -z);
  };

  double operator*(const vector_t& v) const {
    return x * v.x + y * v.y + z * v.z;
  };

  vector_t operator*(double a) const {
    return vector_t(x * a, y * a, z * a);
  };

  vector_t operator/(double a) const {
    return vector_t(x / a, y / a, z / a);
  };

  vector_t operator^(const vector_t& v) const {
    return vector_t(y * v.z - z * v.y,
                    z * v.x - x * v.z,
                    x * v.y - y * v.x);
  };

public:
  double length() const {
    return sqrt(*this * *this);
  };

  vector_t normal() const {
    return *this / length();
  };
};


class point_t {
public:
  double x;
  double y;
  double z;
  double w;

public:
  point_t(double x = 0, double y = 0, double z = 0, double w = 1) : x(x), y(y), z(z), w(w) {};
  
public:
  point_t operator+(const vector_t& v) const {
    return point_t(x + v.x, y + v.y, z + v.z);
  };

  vector_t operator-(const point_t& p) const {
    return vector_t(x - p.x, y - p.y, z - p.z);
  };
};


vector_t::vector_t(const point_t& p) : x(p.x / p.w), y(p.y / p.w), z(p.z / p.w)
{
}


class point_circle_intersect : public std::unary_function<point_t, bool>
{
public:
  point_circle_intersect(const point_t& o, double r) : o_(o), rr_(r * r + EPSILON) {};

public:
  bool operator()(const point_t& p) const {
    vector_t v(p - o_);

    return v * v < rr_;
  };

private:
  point_t o_;
  
  double rr_;
};


class ray_circle_intersect : public std::binary_function<point_t, vector_t, bool>
{
public:
  ray_circle_intersect(const point_t& o, double r) : o_(o), rr_(r * r)
  {
  };

public:
  bool operator()(const point_t& o, const vector_t& d) {
    vector_t p(o - o_);

    double A = d * d;
    double B = d * p;
    double C = p * p - rr_;

    double D = B * B - A * C;

    if (D < 0)
      return false;
    
    D = sqrt(D);

    double t1 = (- B + D) / A;
    double t2 = (- B - D) / A;

    return ! (std::max(t1, t2) < -EPSILON);
  };

private:
  point_t o_;

  double rr_;
};


class point_point_squared_distance : public std::unary_function<point_t, double>
{
public:
  point_point_squared_distance(const point_t& p) : p_(p)
  {
  };

public:
  double operator()(const point_t& p) const {
    vector_t v(p - p_);

    return v * v;
  };

private:
  point_t p_;
};


template <class Operator>
class binary_coupler : public std::binary_function<int, int, bool>
{
public:
  binary_coupler(Operator op, const std::vector<point_t>& points) :
    op_(op), points_(points)
  {
  };

public:
  bool operator()(int a, int b) const {
    return op_(points_[a]) < op_(points_[b]);
  };

private:
  Operator op_;

  const std::vector<point_t>& points_;
};


template <class Operator>
binary_coupler<Operator> make_binary_coupler(Operator op, const std::vector<point_t>& points_)
{
  return binary_coupler<Operator>(op, points_);
}


int main(int argc, char** argv)
{
  while (1) {
    int r, n;
    
    std::cin >> r >> n;

    if (r == 0 && n == 0)
      break;
    
    std::vector<point_t>  points(n);
    std::vector<double>   rs    (n);
    std::vector<vector_t> vs    (n);
    std::vector<int>      valid (n, true);

    for (int i = 0; i < n; i ++) {
      double v;

      std::cin >> points[i].x >> points[i].y >> rs[i] >> v;

      vs[i] = - vector_t(points[i]).normal() * v;
    }

    std::vector<int> index(n);

    for (int i = 0; i < n; i ++)
      index[i] = i;

    int c = 0;

    for (int t = 1; ; t ++) {
      std::vector<point_t> pts(n);
      std::vector<int>     index;

      for (int i = 0; i < n; i ++)
        if (valid[i]) {
          point_t p(points[i] + vs[i] * t);

          if (point_circle_intersect(point_t(), r)(p)) {
            c ++;

            valid[i] = false;
          }
          else {
            pts[i] = p;

            index.push_back(i);
          }
        }

      if (index.empty())
        break;

      int im = std::min_element(ALL(index),
                                make_binary_coupler(point_point_squared_distance(point_t()),
                                                    pts)
                                ) - index.begin();

      for (int i = 0; i < n; i ++)
        if (valid[i])
          if (ray_circle_intersect(pts[i].x, pts[i].y)(point_t(), vector_t(pts[im])))
            valid[i] = false;
    }

    std::cout << c << std::endl;
  }

  return 0;
}

Compiler output:
a.cc:87:44: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
   87 | class point_circle_intersect : public std::unary_function<point_t, bool>
      |                                            ^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/iomanip:42,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
a.cc:106:42: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  106 | class ray_circle_intersect : public std::binary_function<point_t, vector_t, bool>
      |                                          ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
a.cc:141:50: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  141 | class point_point_squared_distance : public std::unary_function<point_t, double>
      |                                                  ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
a.cc:161:36: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  161 | class binary_coupler : public std::binary_function<int, int, bool>
      |                                    ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
a.cc: In function 'int main(int, char**)':
a.cc:241:21: error: 'min_element' is not a member of 'std'; did you mean 'tuple_element'?
  241 |       int im = std::min_element(ALL(index),
      |                     ^~~~~~~~~~~
      |                     tuple_element