hdu 5738 多校2 Eureka 【几何计数】

该博客介绍了如何解决HDU 5738多校比赛中的一道几何计数问题。博主通过枚举每个点,确定相同点和共线点的数量,并利用数学公式计算出满足条件的点集总数。算法涉及到集合论和几何概念的综合应用。
摘要由CSDN通过智能技术生成

思路:
满足题意的点集为共线点集和相同点集,一个集合至少两个点;
无重复枚举每个点,找出相同点个数m,共线点个数 ki (多条线),
包含此点的点集个数为 (2m1m)+sum((sm1)(2k1))
累加

#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;

typedef long long LL;

const int MOD = 1e9 + 7;

LL gcd(LL a, LL b)
{
    if(!b)
        return a;
    return gcd(b, a%b);
}

struct point
{
    int x, y;
    friend bool operator==(const point &a, const point &b)
    {
        return a.x == b.x && a.y == b.y;
    }
    friend bool operator<(const point &a, const point &b)
    {
        if(a.x == b.x)
            return a.y < b.y;
        else
            return a.x < b.x;
    }
};

class line
{
    LL a, b;
public:
    line(point g, point h)
    {
        a = h.y - g.y;
        b = g.x - h.x;
        LL d = gcd(a, b);
        a /= d;
        b /= d;
        if(a < 0)
        {
            a = -a;
            b = -b;
        }
    }
    friend bool operator<(const line &t, const line &t1)
    {
        if(t.a == t1.a)
            return t.b < t1.b;
        else
            return t.a < t1.a;
    }
};

point p[1010];
LL fp[1010];

void init()
{
    fp[0] = 1;
    for(int i = 1; i <= 1000; i++)
    {
        fp[i] = fp[i-1] << 1;
        fp[i] %= MOD;
    }
}

int main(int argc, char const *argv[])
{
    init();                         

    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n;
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
            scanf("%d%d", &p[i].x, &p[i].y);
        sort(p, p+n);

        LL ans = 0;
        for(int i = 0; i < n; i++)
        {
            int m = 1;
            while(i+1 < n && p[i] == p[i+1])
            {
                m++;
                i++;
            }

            ans += (fp[m] - 1 - m);      //相同点集
            ans %= MOD;
            map<line, int> l;
            l.clear();
            for(int j = i+1; j < n; j++)
                l[line(p[i], p[j])] ++;

            for(map<line, int>::iterator it = l.begin(); it != l.end(); it++)
            {
                ans += (fp[m] - 1) * (fp[it->second] - 1);  //共线点集
                ans %= MOD;
            }
        }

        printf("%d\n", ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值