Language: C++

// last update 2012/12/15

#include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> P;

const double eps = 1e-8;
const double pi = acos(-1);

bool equals(double a, double b) { return abs(a - b) < eps; }

bool equals(P a, P b) {
  return equals(a.real(), b.real()) && equals(a.imag(), b.real());
}

namespace std {
  bool operator < (const P &a, const P b) {
    return ( a.real() != b.real()
             ? a.real() < b.real() : a.imag() < b.imag() );
  }
}

struct L : public vector<P> {
  L(P a, P b) {
    push_back(a), push_back(b);
  }
};

struct C {
  P o;
  double r;
  C() {}
  C(P o, double r) : o(o), r(r) {}
};

double norm(P a) { return a.real()*a.real() + a.imag() * a.imag(); }
double abs (P a) { return sqrt(norm(a)); }
double dot  (P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }
double cross(P a, P b) { return a.real()*b.imag() - a.imag()*b.real(); }

bool isOrthogonal(P a, P b) { return equals(dot(a, b), 0.0); }
bool isParallel  (P a, P b) { return equals(cross(a, b), 0.0); }

P project(P s1, P s2, P p) {
  P base = s2 - s1;
  double t = dot(p - s1, base)/norm(base);
  return s1 + base*t;
}

P reflect(P s1, P s2, P p) { return p + (project(s1, s2, p) - p)*2.0; }

P getRotateP(P p, double rad, P o = P(0, 0)) {
  P q = p - o;
  return o + P(q.real()*cos(rad) - q.imag()*sin(rad),
               q.real()*sin(rad) + q.imag()*cos(rad));
}

namespace CCW {
  enum { COUNTER_CLOCKWISE = 1, CLOCKWISE = -1,
         ONLINE_BACK = 2, ONLINE_FRONT = -2,
         ONSEGMENT = 0 };
}

int ccw(P p0, P a, P b) {
  a -= p0;
  b -= p0;
  if(cross(a, b) > eps) return CCW::COUNTER_CLOCKWISE;
  if(cross(a, b) < -eps) return CCW::CLOCKWISE;
  if(dot(a, b) < -eps) return CCW::ONLINE_BACK;
  if(norm(b)-norm(a) > eps) return CCW::ONLINE_FRONT;
  return CCW::ONSEGMENT;
}

// 邱壼?縺ィ邱壼?縺ョ莠、蟾ョ蛻、螳壹?
bool isIntersect(P a1, P a2, P b1, P b2) {
  return ( ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 &&
           ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0 );
}

double getDistanceLP(P s1, P s2, P p) {
  return fabs(cross(s2 - s1, p - s1)/abs(s2 - s1));
}

double getDistanceSP(P s1, P s2, P p) {
  if(dot(s2 - s1, p - s1) < 0.0) return abs(p - s1);
  if(dot(s1 - s2, p - s2) < 0.0) return abs(p - s2);
  return getDistanceLP(s1, s2, p);
}

double getDistance(P a1, P a2, P b1, P b2) {
  if(isIntersect(a1,a2,b1,b2)) return 0.0;
  return min(min(getDistanceSP(a1,a2,b1), getDistanceSP(a1,a2,b2)),
             min(getDistanceSP(b1,b2,a1), getDistanceSP(b1,b2,a2)));
}

// 逶エ邱壹→蜀??莠、蟾ョ蛻、螳壹?謌サ繧雁?縺ッ莠、轤ケ縺ョ謨ー縲?int isIntersect(P s1, P s2, C c) {
  double d = getDistanceLP(s1, s2, c.o);
  if(equals(d, c.r)) return 1;
  else if(d < c.r) return 2;
  else return 0;
}

// 蜀?→蜀??莠、蟾ョ蛻、螳壹?
//  0 : 莠、蟾ョ縲∝?蛹?↑縺?//  1 : 螟夜Κ縺ァ1轤ケ縺ィ謗・縺吶ｋ
//  2 : 2轤ケ縺ァ莠、蟾ョ
// -1 : 蜀?桁縺励※謗・縺吶ｋ
// -2 : 螳悟?縺ォ蜀?桁
int isIntersect(C a, C b) {
  double x = a.o.real() - b.o.real();
  double y = a.o.imag() - b.o.imag();
  double s = a.r + b.r;
  double d = x*x + y*y;
  s *= s;
  if(equals(d, s)) return 1;
  if(d > s) return 0;
  double r = abs(a.r - b.r);
  r *= r;
  if(equals(d, r)) return -1;
  if(d > r) return 2;
  return -2;
}

// 逶エ邱壹→逶エ邱壹?莠、轤ケ縲?P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  // cross 縺ョ隨ヲ蜿キ髢「菫ゅ≠繧?  return a1 + a * cross(b, b1 - a1)/cross(b, a);
}

// 逶エ邱壹→蜀??莠、轤ケ縲?vector<P> getCrossP(P s1, P s2, C c) {
  vector<P> v;
  P p = project(s1, s2, c.o);
  if(isIntersect(s1, s2, c) == 1) {
    v.push_back(p);
  } else {
    double h = abs(p-c.o);
    double d = sqrt(c.r*c.r - h*h);
    P base = s2 - s1;
    v.push_back(p + d*base/abs(base));
    v.push_back(p - d*base/abs(base));
  }
  return v;
}

// 蜀?→蜀??莠、轤ケ縲?vector<P> getCrossP(C c1, C c2) {
  vector<P> v;
  int cp = isIntersect(c1,c2);
  if(cp == 0 || cp == -2) return v;
  
  double ll = norm(c1.o - c2.o);
  double A = ( c1.r * c1.r - c2.r * c2.r + ll ) / ( 2.0 * ll );
  P base = c2.o - c1.o;

  if(abs(cp) == 1) {
    v.push_back(c1.o + A*base);
  } else {
    P n(-base.imag(), base.real());
    n /= abs(n);
    double h = sqrt(c1.r * c1.r - A*A*ll);
    v.push_back(c1.o + A*base + h*n);
    v.push_back(c1.o + A*base - h*n);
  }
  return v;
}


// 2縺、縺ョ繝吶け繝医Ν縺ョ縺ェ縺呵ァ?0 <= rad <= PI)
double getAngle(P a, P b) {
  return acos(dot(a, b)/(abs(a)*abs(b)));
}

// 繝吶け繝医Ν(1, 0)繧貞渕貅悶→縺励◆繝吶け繝医Ν縺ョ隗貞コヲ(-PI <= rad <= PI)
double getAngle(P a) {
  return atan2(a.imag(), a.real());
}

// 2縺、縺ョ逶エ邱壹↓謗・縺吶ｋ蜊雁セв縺ョ蜀?C getC(P a1, P a2, P b1, P b2, double r) {
  P a = a2 - a1;
  P b = b2 - b1;
  if(cross(a, b) < 0) swap(a, b);
  P p = getCrossP(a1, a2, b1, b2);
  double rad = getAngle(a, b);
  double alpha = getAngle(a);
  double d = r/sin(rad/2.0);
  C res;
  res.r = r;
  res.o = p + d * P(cos(alpha + rad/2.0), sin(alpha + rad/2.0));
  return res;
}

// 繝倥Ο繝ウ縺ョ蜈ャ蠑上ｒ逕ィ縺?※荳芽ァ貞ス「縺ョ3霎コ縺ョ髟キ縺輔°繧蛾擇遨阪ｒ豎ゅａ繧?double heron(double a, double b, double c) {
  double s = (a+b+c)/2.0;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}

// 螟夊ァ貞ス「縺ョ髱「遨?double getArea(vector<P> &G) {
  int n = G.size();
  double S = 0;
  for(int i = 0; i < n; ++i) {
    S += cross(G[i], G[(i+1)%n]);
  }
  return S/2.0;
}

// 荳芽ァ貞ス「縺ョ蜀?磁蜀??蜊雁セ?double getIncircleR(P p1, P p2, P p3) {
  double a = abs(p1 - p2);
  double b = abs(p2 - p3);
  double c = abs(p3 - p1);
  return heron(a,b,c)*2.0/(a+b+c);
}

vector<P> convex_hull(vector<P> ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<P> ch(2*n);
  for(int i = 0; i < n; ch[k++] = ps[i++])
    while(k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for(int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--])
    while(k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

vector<P> convex_cut(vector<P> ps, P p1, P p2, int dir = CCW::CLOCKWISE) {
  vector<P> v;
  for(int i = 0; i < ps.size(); ++i) {
    P a = ps[i];
    P b = ps[(i+1)%ps.size()];
    if(ccw(p1, p2, a) != dir) v.push_back(a);
    if(ccw(p1, p2, a)*ccw(p1, p2, b) == -1)
      v.push_back(getCrossP(a, b, p1, p2));
  }
  return v;
}

vector<L> getLine(C a, C b) {
  vector<L> res;
  bool swapped = false;
  if (a.r > b.r) {
    swap(a, b);
    swapped = true;
  }
  int c = isIntersect(a, b);

  if (c == -2) {
    // there are no lines
  } else if (abs(c) == 1) {
    P cp = getCrossP(a, b)[0];
    P base = b.o - a.o;
    P n(-base.imag(), base.real());
    res.push_back(L(cp, cp + n));
  } else {
    {
      if (a.r == b.r) {
        P base = b.o - a.o;
        P n(-base.imag(), base.real());
        n /= abs(n);
        res.push_back(L(a.o + n * a.r, b.o + n * a.r));
        res.push_back(L(a.o - n * a.r, b.o - n * a.r));
      } else {
        double h = b.r - a.r;
        double x = sqrt(norm(a.o - b.o) - h * h);
        vector<P> ps = getCrossP(C(b.o, h), C(a.o, x));
        for (int i = 0; i < ps.size(); ++i) {
          P n = ps[i] - b.o;
          n /= abs(n);
          res.push_back(L(a.o + n * a.r, ps[i] + n * a.r));
        }
      }
    }
    {
      double h = b.r + a.r;
      double x = sqrt(norm(a.o - b.o) - h * h);
      vector<P> ps = getCrossP(C(b.o, h), C(a.o, x));
      for (int i = 0; i < ps.size(); ++i) {
        P n = b.o - ps[i];
        n /= abs(n);
        res.push_back(L(a.o + n * a.r, ps[i] + n * a.r));
      }
    }
  }

  if (swapped) {
    for (int i = 0; i < res.size(); ++i) {
      swap(res[i][0], res[i][1]);
    }
  }
  return res;
}

// aoj 2201
int main(void) {
  int N;
  vector<P> p;
  vector<double> r, m;
  while(cin >> N && N) {
    p.resize(N);
    r.resize(N);
    m.resize(N);
    for(int i = 0; i < N; ++i) {
      cin >> p[i].real() >> p[i].imag() >> r[i] >> m[i];
    }
    if(N == 1) {
      cout << 1 << endl;
      continue;
    }
    vector<L> ls;
    for(int i = 0; i < N; ++i) {
      for(int j = i+1; j < N; ++j) {
        vector<L> tmp;
        tmp = getLine(C(p[i], r[i]), C(p[j], r[j]));
        for(int k = 0; k < tmp.size(); ++k) ls.push_back(tmp[k]);
        tmp = getLine(C(p[i], r[i]+m[i]), C(p[j], r[j]));
        for(int k = 0; k < tmp.size(); ++k) ls.push_back(tmp[k]);
        tmp = getLine(C(p[i], r[i]), C(p[j], r[j]+m[j]));
        for(int k = 0; k < tmp.size(); ++k) ls.push_back(tmp[k]);
        tmp = getLine(C(p[i], r[i]+m[i]), C(p[j], r[j]+m[j]));
        for(int k = 0; k < tmp.size(); ++k) ls.push_back(tmp[k]);
      }
    }

    int res = 0;
    for(int k = 0; k < ls.size(); ++k) {
      int cnt = 0;
      for(int i = 0; i < N; ++i) {
        double d = getDistanceLP(ls[k][0], ls[k][1], p[i]);
        if((equals(d, r[i]) || d > r[i]) &&
           (equals(d-r[i], m[i]) || d-r[i] < m[i])) ++cnt;
      }
      res = max(res, cnt);
    }
    cout << res << endl;
  }
  return 0;
}

Compiler output:
a.cc:102:28: error: 's1' was not declared in this scope; did you mean 'y1'?
  102 |   double d = getDistanceLP(s1, s2, c.o);
      |                            ^~
      |                            y1
a.cc:102:32: error: 's2' was not declared in this scope
  102 |   double d = getDistanceLP(s1, s2, c.o);
      |                                ^~
a.cc:102:36: error: 'c' was not declared in this scope
  102 |   double d = getDistanceLP(s1, s2, c.o);
      |                                    ^
a.cc:103:3: error: expected unqualified-id before 'if'
  103 |   if(equals(d, c.r)) return 1;
      |   ^~
a.cc:104:3: error: expected unqualified-id before 'else'
  104 |   else if(d < c.r) return 2;
      |   ^~~~
a.cc:105:3: error: expected unqualified-id before 'else'
  105 |   else return 0;
      |   ^~~~
a.cc:106:1: error: expected declaration before '}' token
  106 | }
      | ^
a.cc:129:9: error: 'a2' was not declared in this scope; did you mean 'a'?
  129 |   P a = a2 - a1;
      |         ^~
      |         a
a.cc:129:14: error: 'a1' was not declared in this scope; did you mean 'y1'?
  129 |   P a = a2 - a1;
      |              ^~
      |              y1
a.cc:130:9: error: 'b2' was not declared in this scope; did you mean 'b'?
  130 |   P b = b2 - b1;
      |         ^~
      |         b
a.cc:130:14: error: 'b1' was not declared in this scope; did you mean 'y1'?
  130 |   P b = b2 - b1;
      |              ^~
      |              y1
a.cc:132:1: error: expected declaration before '}' token
  132 | }
      | ^
a.cc:136:17: error: 's1' was not declared in this scope; did you mean 'y1'?
  136 |   P p = project(s1, s2, c.o);
      |                 ^~
      |                 y1
a.cc:136:21: error: 's2' was not declared in this scope
  136 |   P p = project(s1, s2, c.o);
      |                     ^~
a.cc:136:25: error: 'c' was not declared in this scope
  136 |   P p = project(s1, s2, c.o);
      |                         ^
a.cc:137:3: error: expected unqualified-id before 'if'
  137 |   if(isIntersect(s1, s2, c) == 1) {
      |   ^~
a.cc:139:5: error: expected unqualified-id before 'else'
  139 |   } else {
      |     ^~~~
a.cc:146:3: error: expected unqualified-id before 'return'
  146 |   return v;
      |   ^~~~~~
a.cc:147:1: error: expected declaration before '}' token
  147 | }
      | ^
a.cc:150:13: error: redefinition of 'std::vector<std::complex<double> > v'
  150 |   vector<P> v;
      |             ^
a.cc:135:13: note: 'std::vector<std::complex<double> > v' previously declared here
  135 |   vector<P> v;
      |             ^
a.cc:151:24: error: 'c1' was not declared in this scope; did you mean 'y1'?
  151 |   int cp = isIntersect(c1,c2);
      |                        ^~
      |                        y1
a.cc:151:27: error: 'c2' was not declared in this scope; did you mean 'cp'?
  151 |   int cp = isIntersect(c1,c2);
      |                           ^~
      |                           cp
a.cc:152:3: error: expected unqualified-id before 'if'
  152 |   if(cp == 0 || cp == -2) return v;
      |   ^~
a.cc:154:20: error: 'c1' was not declared in this scope; did you mean 'y1'?
  154 |   double ll = norm(c1.o - c2.o);
      |                    ^~
      |                    y1
a.cc:154:27: error: 'c2' was not declared in this scope; did you mean 'cp'?
  154 |   double ll = norm(c1.o - c2.o);
      |                           ^~
      |                           cp
a.cc:155:16: error: 'c1' was not declared in this scope; did you mean 'y1'?
  155 |   double A = ( c1.r * c1.r - c2.r * c2.r + ll ) / ( 2.0 * ll );
      |                ^~
      |                y1
a.cc:155:23: error: 'c1' was not declared in this scope; did you mean 'y1'?
  155 |   double A = ( c1.r * c1.r - c2.r * c2.r + ll ) / ( 2.0 * ll );
      |                       ^~
      |                       y1
a.cc:155:30: error: 'c2' was not declared in this scope; did you mean 'cp'?
  155 |   double A = ( c1.r * c1.r - c2.r * c2.r + ll ) / ( 2.0 * ll );
      |                              ^~
      |                              cp
a.cc:155:37: error: 'c2' was not declared in this scope; did you mean 'cp'?
  155 |   double A = ( c1.r * c1.r - c2.r * c2.r + ll ) / ( 2.0 * ll );
      |                                     ^~
      |                                     cp
a.cc:156:12: error: 'c2' was not declared in this scope; did you mean 'cp'?
  156 |   P base = c2.o - c1.o;
      |            ^~
      |            cp
a.cc:156:19: error: 'c1' was not declared in this scope; did you mean 'y1'?
  156 |   P base = c2.o - c1.o;
      |                   ^~
      |                   y1
a.cc:158:3: error: expected unqualified-id before 'if'
  158 |   if(abs(cp) == 1) {
      |   ^~
a.cc:160:5: error: expected unqualified-id before 'else'
  160 |   } else {
      |     ^~~~
a.cc:167:3: error: expected unqualified-id before 'return'
  167 |   return v;
      |   ^~~~~~
a.cc:168:1: error: expected declaration before '}' token
  168 | }
      | ^
a.cc:182:5: error: redefinition of 'P a'
  182 |   P a = a2 - a1;
      |     ^
a.cc:129:5: note: 'P a' previously declared here
  129 |   P a = a2 - a1;
      |     ^
a.cc:182:9: error: 'a2' was not declared in this scope; did you mean 'a'?
  182 |   P a = a2 - a1;
      |         ^~
      |         a
a.cc:182:14: error: 'a1' was not declared in this scope; did you mean 'y1'?
  182 |   P a = a2 - a1;
      |              ^~
      |              y1
a.cc:183:5: error: redefinition of 'P b'
  183 |   P b = b2 - b1;
      |     ^
a.cc:130:5: note: 'P b' previously declared here
  130 |   P b = b2 - b1;
      |     ^
a.cc:183:9: error: 'b2' was not declared in this scope; did you mean 'b'?
  183 |   P b = b2 - b1;
      |         ^~
      |         b
a.cc:183:14: error: 'b1' was not declared in this scope; did you mean 'y1'?
  183 |   P b = b2 - b1;
      |              ^~
      |              y1
a.cc:184:3: error: expected unqualified-id before 'if'
  184 |   if(cross(a, b) < 0) swap(a, b);
      |   ^~
a.cc:185:5: error: redefinition of 'P p'
  185 |   P p = getCrossP(a1, a2, b1, b2);
      |     ^
a.cc:136:5: note: 'P p' previously declared here
  136 |   P p = project(s1, s2, c.o);
      |     ^
a.cc:185:19: error: 'a1' was not declared in this scope; did you mean 'y1'?
  185 |   P p = getCrossP(a1, a2, b1, b2);
      |                   ^~
      |                   y1
a.cc:185:23: error: 'a2' was not declared in this scope; did you mean 'a'?
  185 |   P p = getCrossP(a1, a2, b1, b2);
      |                       ^~
      |                       a
a.cc:185:27: error: 'b1' was not declared in this scope; did you mean 'y1'?
  185 |   P p = getCrossP(a1, a2, b1, b2);
      |                           ^~
      |                           y1
a.cc:185:31: error: 'b2' was not declared in this scope; did you mean 'b'?
  185 |   P p = getCrossP(a1, a2, b1, b2);
      |                               ^~
      |                               b
a.cc:185:9: error: 'getCrossP' was not declared in this scope
  185 |   P p = getCrossP(a1, a2, b1, b2);
      |         ^~~~~~~~~
a.cc:188:10: error: redefinition of 'double d'
  188 |   double d = r/sin(rad/2.0);
      |          ^
a.cc:102:10: note: 'double d' previously defined here
  102 |   double d = getDistanceLP(s1, s2, c.o);
      |          ^
a.cc:188:14: error: 'r' was not declared in this scope
  188 |   double d = r/sin(rad/2.0);
      |              ^
a.cc:190:3: error: 'res' does not name a type
  190 |   res.r = r;
      |   ^~~
a.cc:191:3: error: 'res' does not name a type
  191 |   res.o = p + d * P(cos(alpha + rad/2.0), sin(alpha + rad/2.0));
      |   ^~~
a.cc:192:3: error: expected unqualified-id before 'return'
  192 |   return res;
      |   ^~~~~~
a.cc:193:1: error: expected declaration before '}' token
  193 | }
      | ^
a.cc:196:19: error: 'c' was not declared in this scope
  196 |   double s = (a+b+c)/2.0;
      |                   ^
a.cc:197:3: error: expected unqualified-id before 'return'
  197 |   return sqrt(s*(s-a)*(s-b)*(s-c));
      |   ^~~~~~
a.cc:198:1: error: expected declaration before '}' token
  198 | }
      | ^
a.cc:201:11: error: 'G' was not declared in this scope
  201 |   int n = G.size();
      |           ^
a.cc:203:3: error: expected unqualified-id before 'for'
  203 |   for(int i = 0; i < n; ++i) {
      |   ^~~
a.cc:203:18: error: 'i' does not name a type
  203 |   for(int i = 0; i < n; ++i) {
      |                  ^
a.cc:203:25: error: expected unqualified-id before '++' token
  203 |   for(int i = 0; i < n; ++i) {
      |                         ^~
a.cc:206:3: error: expected unqualified-id before 'return'
  206 |   return S/2.0;
      |   ^~~~~~
a.cc:207:1: error: expected declaration before '}' token
  207 | }
      | ^
a.cc:210:10: error: conflicting declaration 'double a'
  210 |   double a = abs(p1 - p2);
      |          ^
a.cc:129:5: note: previous declaration as 'P a'
  129 |   P a = a2 - a1;
      |     ^
a.cc:210:18: error: 'p1' was not declared in this scope; did you mean 'y1'?
  210 |   double a = abs(p1 - p2);
      |                  ^~
      |                  y1
a.cc:210:23: error: 'p2' was not declared in this scope; did you mean 'pi'?
  210 |   double a = abs(p1 - p2);
      |                       ^~
      |                       pi
a.cc:211:10: error: conflicting declaration 'double b'
  211 |   double b = abs(p2 - p3);
      |          ^
a.cc:130:5: note: previous declaration as 'P b'
  130 |   P b = b2 - b1;
      |     ^
a.cc:211:18: error: 'p2' was not declared in this scope; did you mean 'pi'?
  211 |   double b = abs(p2 - p3);
      |                  ^~
      |                  pi
a.cc:211:23: error: 'p3' was not declared in this scope; did you mean 'pi'?
  211 |   double b = abs(p2 - p3);
      |                       ^~
      |                       pi
a.cc:212:18: error: 'p3' was not declared in this scope; did you mean 'pi'?
  212 |   double c = abs(p3 - p1);
      |                  ^~
      |                  pi
a.cc:212:23: error: 'p1' was not declared in this scope; did you mean 'y1'?
  212 |   double c = abs(p3 - p1);
      |                       ^~
      |                       y1
a.cc:213:3: error: expected unqualified-id