HDU5738 Eureka

来源:互联网 发布:好压mac 编辑:程序博客网 时间:2024/06/05 01:53

题目链接


分析

代码

#define mod 1000000007#define maxm#define maxn 1010int 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);    }}