POJ 1106 Transmitters

给定一些点,和一个圆心坐标,求一个以这个点为圆心的半圆能最多能圈下多少点。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define hPI 1.5707963267949
#define eps 1e-8
struct point
{
    double x;
    double y;
};
double cross(point a,point b,point c){
    a.x-=c.x;a.y-=c.y;
    b.x-=c.x;b.y-=c.y;
    return a.x*b.y-a.y*b.x;
}
double mul(point a,point b,point c)
{
    a.x-=c.x;a.y-=c.y;
    b.x-=c.x;b.y-=c.y;
    return a.x*b.x+a.y*b.y;
}
double dist(point a,point b)
{
    return sqrt(mul(a,a,b));
}
double angle(point a,point b,point c)
{
    return cross(a,b,c)/dist(a,c)/dist(b,c);
}
int main()
{
    double r,t;
    point p[200],o;
    int lp,i,j,ans,t1,t2;
    while (scanf("%lf%lf%lf",&o.x,&o.y,&r) != EOF)
    {
        if (r < 0)
            break;
        ans=0;
        scanf("%d",&lp);
        for (i=0; i<lp; i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
        for (i=0; i<lp; i++)
        {
            t1=1;
            t2=1;
            t=dist(p[i],o);
            if (t > r)
                continue;
            for (j=0; j<lp; j++)
            {
                if (i == j)
                    continue;
                t=dist(p[j],o);
               // printf("%d %d %lf ",i,j,t);
                if (t > r)
                    continue;
                t=angle(p[i],p[j],o);
                //printf(" %lf\n",t);
                if (t > 0)
                    t1++;
                else if (t < 0)
                    t2++;
                else if (fabs(t-0.0) < eps)
                {
                    t1++;
                    t2++;
                }
            }
           // printf("\nt1=%d t2=%d\n",t1,t2);
            t1=t1>t2?t1:t2;
            ans=ans>t1?ans:t1;
        }
        printf("%d\n",ans);
    }
}


你可能感兴趣的:(POJ 1106 Transmitters)