Problem p00090 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A) (A).begin(), (A).end()
#define DUMP(A) cout << #A << "=" << (A) << endl
#define SIZE(A) (int)((A).size())
#define P2(A) ((A) * (A))
using namespace std;
typedef long long ll;

int main() {
  int n;
  for (;;) {
    scanf("%d\n", &n);
    if (n == 0)
      break;
    vector<double> xs(n), ys(n);
    for (int i = 0; i < n; i++) {
      scanf("%lf %lf\n", &xs[i], &ys[i]);
    }
    if (n == 1) {
      printf("1\n");
      continue;
    }
    int ma = 1;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        double mx = (xs[i] + xs[j]) / 2, my = (ys[i] + ys[j]) / 2,
               vlen = sqrt(P2(xs[i] - xs[j]) + P2(ys[i] - ys[j])),
               llen = sqrt(1 - (P2(xs[i] - mx) + P2(ys[i] - my)));
        if (vlen >= 2.00005)
          continue;
        double p1x = mx + (ys[i] - ys[j]) * (llen / vlen),
               p1y = my - (xs[i] - xs[j]) * (llen / vlen);
        double p2x = mx - (ys[i] - ys[j]) * (llen / vlen),
               p2y = my + (xs[i] - xs[j]) * (llen / vlen);
        int now1 = 0, now2 = 0;
        for (int k = 0; k < n; k++) {
          if (P2(xs[k] - p1x) + P2(ys[k] - p1y) <= 1.00005)
            now1++;
          if (P2(xs[k] - p2x) + P2(ys[k] - p2y) <= 1.00005)
            now2++;
        }
        ma = max(now1, ma);
        ma = max(now2, ma);
      }
    }
    printf("%d\n", ma);
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A) (A).begin(), (A).end()
#define DUMP(A) cout << #A << "=" << (A) << endl
#define SIZE(A) (int)((A).size())
#define P2(A) ((A) * (A))
using namespace std;
typedef long long ll;

int main() {
  int n;
  for (;;) {
    scanf("%d\n", &n);
    if (n == 0)
      break;
    vector<double> xs(n), ys(n);
    for (int i = 0; i < n; i++) {
      scanf("%lf,%lf\n", &xs[i], &ys[i]);
    }
    if (n == 1) {
      printf("1\n");
      continue;
    }
    int ma = 1;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        double mx = (xs[i] + xs[j]) / 2, my = (ys[i] + ys[j]) / 2,
               vlen = sqrt(P2(xs[i] - xs[j]) + P2(ys[i] - ys[j])),
               llen = sqrt(1 - (P2(xs[i] - mx) + P2(ys[i] - my)));
        if (vlen >= 2.00005)
          continue;
        double p1x = mx + (ys[i] - ys[j]) * (llen / vlen),
               p1y = my - (xs[i] - xs[j]) * (llen / vlen);
        double p2x = mx - (ys[i] - ys[j]) * (llen / vlen),
               p2y = my + (xs[i] - xs[j]) * (llen / vlen);
        int now1 = 0, now2 = 0;
        for (int k = 0; k < n; k++) {
          if (P2(xs[k] - p1x) + P2(ys[k] - p1y) <= 1.00005)
            now1++;
          if (P2(xs[k] - p2x) + P2(ys[k] - p2y) <= 1.00005)
            now2++;
        }
        ma = max(now1, ma);
        ma = max(now2, ma);
      }
    }
    printf("%d\n", ma);
  }
}