HDU5738 Eureka

题目链接


分析

代码

#define mod 1000000007
#define maxm
#define maxn 1010
int a[maxn], b[maxn];
map<pair<int, int>, int> mp;
ll pow_mod(ll x) {
    ll a = 2, ans = 1;
    while (x) {
        if (x & 1) ans = ans * a % mod;
        a = a * a % mod;
        x >>= 1;
    }
    return ans % mod;
}
int main()
{/*
    #ifdef ONLINE_JUDGE
        freopen("aplusb.in", "r", stdin);
        freopen("aplusb.out", "w", stdout);
    #endif*/
    // ios::sync_with_stdio(false);
    int t, n;

    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%d%d", &a[i], &b[i]);
        }
        ll ans = 0;
        //printf("%d\n", __gcd(0, -9));
        for (int i = 0; i < n; i++) {
            mp.clear();
            int cnt = 0, ccnt = 0;
            for (int j = i + 1; j < n; j++) {
                if (a[i] == a[j] && b[j] == b[i]) {
                    ccnt++; 
                } else if (a[i] == a[j]) {
                    cnt++;  
                } else {
                    int x = __gcd(b[i] - b[j], a[i] - a[j]);
                    int y = (b[i] - b[j]) / x;
                    int z = (a[i] - a[j]) / x;
                    if (y <= 0 && z < 0) {
                        y = -y, z = -z;
                    } else if (y < 0) {
                        y = -y, z = -z;
                    }
                    mp[make_pair(y, z)]++;
                }
            }
            ll pp = pow_mod(ccnt);
            ans = (ans + pp - 1 + mod) % mod;
            ans = (ans + pp * ((pow_mod(cnt) - 1 + mod) % mod) % mod) % mod;
            for (auto it : mp) {
                int x = it.second;
                ans = (ans + pp * ((pow_mod(1ll * x) - 1 + mod) % mod) % mod) % mod;
            }
        }
        printf("%lld\n", ans);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值