题意:一个单位圆最多能覆盖平面上多少点。
解题思路:一个覆盖最多点的圆,必然至少有两个点在圆上。枚举两个点,求过这两个点的单位圆,判断有多少个点在圆中,枚举N^2,判断N
参考博客:http://www.cnblogs.com/-sunshine/archive/2012/10/11/2719859.html
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn = 305;
const double eps = 1e-8;
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x, y = _y;
}
}p[maxn];
int n;
double dis(Point p1,Point p2)
{
return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
Point get_circle(Point p1,Point p2)
{
Point mid = Point((p1.x+p2.x)/2,(p1.y+p2.y)/2);
double angle = atan2(p1.x-p2.x,p2.y-p1.y);
double d = sqrt(1-dis(p1,mid)*dis(p1,mid));
return Point(mid.x+d*cos(angle),mid.y+d*sin(angle));
}
int main()
{
while(scanf("%d",&n),n)
{
for(int i = 0; i < n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int ans = 1;
for(int i = 0;i < n; i++){
for(int j = i + 1; j < n; j++){
if(dis(p[i],p[j]) > 2.0) continue;
Point central = get_circle(p[i],p[j]);
int cnt = 0;
for(int k = 0;k < n; k++)
if(dis(central,p[k]) < 1.0 + eps)
cnt++;
ans=max(ans,cnt);
}
}
printf("%d\n",ans);
}
return 0;
}