poj 1981 单位圆套最多点

题意:

给n(300)个点,用单位圆去套他们,问最多能套多少个点。


解析:

点击打开链接


直接当作单位圆套最多点的模板吧,用极脚来排序。


代码:

#pragma comment(linker, "/STACK:1677721600")
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define LL long long
#define lson lo,mi,rt<<1
#define rson mi+1,hi,rt<<1|1
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a,b) memset(a,b,sizeof(a))
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)

using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double ee = exp(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 300 + 10;
const double pi = acos(-1.0);
const LL iinf = 0x3f3f3f3f3f3f3f3f;

struct Point
{
    double x, y;
    Point(){}
    Point(double _x, double _y)
    {
        x = _x;
        y = _y;
    }
} point[maxn];

struct polarAngle
{
    double angle;
    bool tag;       //起点or终点

    const bool operator<(const polarAngle &other)const
    {
        if (angle == other.angle)
            return tag > other.tag;
        return angle < other.angle;
    }
} polarangle[maxn];

double dist(Point a, Point b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

int maxCircleCover(int n, double r)
{
    int res = 1;
    for (int i = 0; i < n; i++)
    {
        int tot = 0;
        double d;
        for (int j = 0; j < n; j++)
        {
            if (i != j && (d = dist(point[i], point[j])) <= 2)
            {
                double phi = acos(d / 2);
                double theta = atan2(point[j].y - point[i].y, point[j].x - point[i].x);
                polarangle[tot].angle = theta - phi;
                polarangle[tot++].tag = true;

                polarangle[tot].angle = theta + phi;
                polarangle[tot++].tag = false;
            }
        }
        sort(polarangle, polarangle + tot);
        int sum = 1;
        for (int j = 0; j < tot; j++)
        {
            if (polarangle[j].tag)
                sum++;
            else
                sum--;
            res = Max(res, sum);
        }
    }
    return res;
}

Point readPoint()
{
    double x, y;
    scanf("%lf %lf", &x, &y);
    return Point(x, y);
}

int main()
{
#ifdef LOCAL
    FIN;
#endif // LOCAL
    int n;
    while (~scanf("%d", &n) && n)
    {
        for (int i = 0; i < n; i++)
        {
            point[i] = readPoint();
        }
        printf("%d\n", maxCircleCover(n, 1.0));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值