Go: package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

func main() {
	for {
		var n int
		fmt.Scan(&n)

		if n == 0 {
			return
		}

		arr := make([]complex128, n)

		for i := 0; i < n; i++ {
			var x, y float64

			fmt.Scanf("%f%f", &x, &y)

			arr[i] = complex(x, y)
		}

		max := 1
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				sub := arr[j] - arr[i]

				if cmplx.Abs(sub) >= 2 {
					continue
				}
				sum := arr[j] + arr[i]

				v := 1
				{
					halfd := cmplx.Abs(sub / 2)

					center := sum/2 + sub*cmplx.Rect(math.Sqrt(1-halfd*halfd)/cmplx.Abs(sub), float64(v)*math.Pi/2)

					counter := 0
					for k := 0; k < n; k++ {
						if i == k || j == k || cmplx.Abs(arr[k]-center) <= 1 {
							counter++
						}
					}
					if max < counter {
						max = counter
					}
				}

				v = -1
				{
					halfd := cmplx.Abs(sub / 2)

					center := sum/2 + sub*cmplx.Rect(math.Sqrt(1-halfd*halfd)/cmplx.Abs(sub), float64(v)*math.Pi/2)

					counter := 0
					for k := 0; k < n; k++ {
						if i == k || j == k || cmplx.Abs(arr[k]-center) <= 1 {
							counter++
						}
					}
					if max < counter {
						max = counter
					}
				}

			}
		}

		fmt.Println(max)
	}
}

C++: #include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;

#include <complex>

typedef complex<double> P;

int N=0;
P p[302];
int CountPointsInCircle(P c){
    int cnt=0;
    for(int i=0;i<N;i++){
        if(abs(p[i]-c)<=1.0001){
            cnt++;
        }
    }
    return cnt;
}

int main(){
    while(1){
        cin>>N;
        if(N==0)break;        
        for(int i=0;i<N;i++){
            double x,y;
            cin>>x>>y;
            p[i]=P(x,y);
        }
        int ans=0;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                P mid = P((p[i].real()+p[j].real())/2,(p[i].imag()+p[j].imag())/2);
                double dist = abs(p[i]-p[j]);
                if(dist>2.0001){
                    continue;
                }
                P n1  = ((p[i]-p[j]) *P(0, 1))/dist;
                P n2  = ((p[i]-p[j]) *P(0,-1))/dist;
                P c1= mid + n1*sqrt(1.0-dist/2.0*dist/2.0);
                P c2= mid + n2*sqrt(1.0-dist/2.0*dist/2.0);
                int ans1=CountPointsInCircle(c1);
                int ans2=CountPointsInCircle(c2);
                ans=max(ans,max(ans1,ans2));
            }
        }
        if(ans==0){
            cout<<1<<endl;
        }else{
            cout<<ans<<endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<math.h>
#include<vector>
using namespace std;

// 点
class Point {
  public:
    float x, y;
    Point(double ix = 0.0, double iy = 0.0) {
      set(ix, iy);
    }
    void set(double ix = 0.0, double iy = 0.0) {
      x = ix;
      y = iy;
    }
    void copy(Point p) {
      x = p.x;
      y = p.y;
    }
    double length() {
      return sqrt(x * x + y * y);
    }
    double distanceTo(Point p) {
      double dx = p.x - x, dy = p.y - y;
      return sqrt(dx * dx + dy * dy);
    }
    void setCentroidOf(Point p1, Point p2) {
      x = (p1.x + p2.x) / 2;
      y = (p1.y + p2.y) / 2;
    }
};

int main() {
  vector<int> results;
  while (true) {
    // 入力
    int n;
    cin >> n;
    if (n == 0) break;
    vector<Point> p(n);
    for (int i=0; i<n; i++) {
      double x, y;
      cin >> x >> y;
      p[i].set(x, y);
    }
    
    const int nC2 = n * (n - 1) / 2 + n;
    vector<Point> px(n); // 現時点で有力な点
    for (int i=0; i<n; i++) px[i].copy(p[i]);
    vector<Point> cp(nC2); // 中点たち
    int previousMaxScore = 0; // 前回のループでの最高スコア
    int maxScoreConst = 0; // 同じ最高スコアが連続して記録された回数
    while (true) {
      // 与えられた点の中点たち（+もとの点）を候補点とする
      int cpi = 0;
      for (int i=0; i<n-1; i++) {
	for (int j=i+1; j<n; j++) {
	  cp[cpi++].setCentroidOf(px[i], px[j]);
	}
      }
      for (int i=0; i<n; i++) cp[cpi++].copy(px[i]);
      // 各点のスコアを算出
      vector<int> scores(nC2);
      for (int i=0; i<nC2; i++) {
	scores[i] = 0;
	for (int j=0; j<n; j++) {
	  if (cp[i].distanceTo(p[j]) <= 1) scores[i]++;
	}
      }
      // cpをスコア降順にバブルソート
      for (int i=0; i<nC2; i++) {
	for (int j=0; j<nC2-1; j++) {
	  if (scores[j] < scores[j + 1]) {
	    double jx = cp[j].x, jy = cp[j].y;
	    cp[j].copy(cp[j + 1]);
	    cp[j + 1].set(jx, jy);
	    int js = scores[j];
	    scores[j] = scores[j + 1];
	    scores[j + 1] = js;
	  }
	}
      }
      // このループの最大スコア
      int maxScore = scores[0];
      //cout << maxScore << " -> ";
      if (maxScore == previousMaxScore) {
	// 最大スコアが5回連続で更新されなかったら確定
	previousMaxScore = maxScore;
	if (++maxScoreConst >= 5) break;
      } else {
	previousMaxScore = maxScore;
	maxScoreConst = 0;
      }
      // スコアが上位nの点を次のループの中点の素として採用
      for (int i=0; i<n; i++) px[i].copy(cp[i]);
    }
    
    results.push_back(previousMaxScore);
    //cout << endl;
  }
  
  int size = results.size();
  for (int i=0; i<size; i++) {
    cout << results[i] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000000001
using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;

typedef complex<double> pt;

int main(){
	pt p[310];
	int i,j,ii;
	int n;
	
	while(1){
		cin >> n;
		if(n==0) break;
		for(i=0;i<n;i++){
			double x,y;
			scanf("%lf %lf",&x,&y);
			p[i] = pt(x,y);
		}
		
		int mx=1;
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){
				double l = abs(p[i]-p[j]);
				double k = sqrt(1-(l*l/4.0));
				pt m = (p[i]+p[j])/2.0;
				pt v(-imag(p[i]-p[j]),real(p[i]-p[j]));
				double r = abs(v);
				v= v*k/r;
				int cnt;
				
				p[n] = m+v;
				cnt=0;
				for(ii=0;ii<n;ii++){
					if(norm(p[ii]-p[n])<=1.000001) cnt++;
				}
				mx = max(mx,cnt);
				
				p[n]=m-v;
				cnt=0;
				for(ii=0;ii<n;ii++){
					if(norm(p[ii]-p[n])<=1.000001) cnt++;
				}
				mx = max(mx,cnt);
			}
		}
		cout << mx << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef complex<double> P;

const double eps = 1e-8;
const int MAXN = 333;
int N;
P ps[MAXN];

int calc(P c) {
  int res = 0;
  for(int i = 0; i < N; ++i) {
    double d = abs(c - ps[i]);
    if(d < 1+eps) ++res;
  }
  return res;
}

int main() {
  for(; cin >> N && N; ) {
    for(int i = 0; i < N; ++i) {
      cin >> ps[i].real() >> ps[i].imag();
    }
    int res = 0;
    for(int i = 0; i < N; ++i) {
      for(int j = i+1; j < N; ++j) {
        double d = abs(ps[i] - ps[j]);
        P base = ps[i] - ps[j];
        P m = ps[j] + base / 2.0;
        P base2(-base.imag(), base.real());
        double a = sqrt(1.0 - d * d / 4.0);
        base2 = base2 / abs(base2) * a;
        res = max(res, max(calc(m + base2), calc(m - base2)));
      }
    }
    cout << res << endl;
  }
  return 0;
}