[NOI2013]向量内积

博客内容仅为一个转载链接https://www.cnblogs.com/luoyibujue/p/10896821.html,未包含其他关键信息技术信息。
/*
以现在的机器速度, 不使用bitset的暴力是能跑到75分的
考虑在取模意义下的特殊情况, 维护a数组的每一维的前缀和,整体来做, 那么在一次统计中得不到一个答案的概率是$\frac{1}{2}$
至于取mod为三的情况 我们发现虽然mod不为0的情况可能是1 或者2 但是他们两个在mod3 意义下平方后都是1
按照这个性质维护即可
 
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#define ll long long
#define M 100010
#define mmp make_pair
using namespace std;
int read() {
    int nm = 0, f = 1;
    char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
    return nm * f;
}
int a[M][105], n, d, k, rd[M], tmp[105][105], tmd[105];


int work(int now) {
    int ans = 0;
    if(k == 2) {
        for(int i = 1; i <= d; i++) {
            ans ^= a[now][i] * tmd[i];
            tmd[i] ^= a[now][i];
        }
    } else {
        for(int i = 1; i <= d; i++)
            for(int j = 1; j <= d; j++) {
                ans += a[now][i] * a[now][j] * tmp[i][j];
                tmp[i][j] += a[now][i] * a[now][j];
            }
    }
    return ans % k;
}


bool check(int i, int j) {
    int ans = 0;
    for(int z = 1; z <= d; z++) ans += a[i][z] * a[j][z];
    ans %= k;
    return ans == 0;
}

int main() {
    srand(20020216);
    n = read(), d = read(), k = read();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= d; j++)
            a[i][j] = read() % k;
    }
    for(int i = 1; i <= n; i++) rd[i] = i;
    for(int T = 1; T; T--) {
        random_shuffle(rd + 1, rd + n + 1);
        for(int i = 1; i <= n; i++) {
            if(work(rd[i]) == ((i - 1) % k)) continue;
            //  cout << "!";
            for(int j = 1; j < i; j++) if(check(rd[i], rd[j])) {
                    if(rd[i] > rd[j]) swap(rd[i], rd[j]);
                    cout << rd[i] << " " << rd[j] << "\n";
                    return 0;
                }
        }
        memset(tmp, 0, sizeof(tmp));
        memset(tmd, 0, sizeof(tmd));
    }
    puts("-1 -1");
    return 0;
}
/*
5 2 3
1 1
1 1
1 1
1 1
1 1

*/

转载于:https://www.cnblogs.com/luoyibujue/p/10896821.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值