HDU 1077 Catching Fish

题意: 给出 N 只鱼的坐标,问用半径为 1  的渔网做多可以捕到多少鱼。

分析: 以每条鱼为圆心,作半径为1 的圆,枚举两两圆的交点,比较以每个交点为圆心半径 1 的渔网最多捕获的鱼数。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
const double eps=1e-6;
struct node
{
    double x,y;
}q[305];
double dis(node a,node b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
node find_c(node p1,node p2)
{
    node p3,mid,center;
    double b,c,degree;
    p3.x=p2.x-p1.x;
    p3.y=p2.y-p1.y;
    mid.x=(p1.x+p2.x)/2;
    mid.y=(p1.y+p2.y)/2;
    b=dis(p1,mid);
    c=sqrt(1-b);
    if(fabs(p3.y)<eps)
    {
        center.x=mid.x;
        center.y=mid.y+c;
    }
    else 
    {
        degree=atan(-p3.x/p3.y);
        center.x=mid.x+c*cos(degree);
        center.y=mid.y+c*sin(degree);
    }
    return center;
}
int main()
{
    node center;
    int n,T,res,t,i,j,k;
    double tmp;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
            scanf("%lf%lf",&q[i].x,&q[i].y);
        res=1;
        for(i=0;i<n;i++)
            for(j=i+1;j<n;j++)
            {
                if(dis(q[i],q[j])>4)
                    continue;
                t=0;
                center=find_c(q[i],q[j]);
                for(k=0;k<n;k++)
                {
                    tmp=dis(center,q[k]);
                    if(tmp<1.000001)
                        t++;
                }
                if(t>res)
                    res=t;
            }
        printf("%d\n",res);
    }
    return 0;
}

 

posted @ 2012-08-03 10:59  'wind  阅读(207)  评论(0编辑  收藏  举报