zoukankan      html  css  js  c++  java
  • 3.31 每日一题题解

    Arpa’s obvious problem and Mehrdad’s terrible solution

    涉及知识点:

    • 数学

    solution:

    • 题意就是让你找出给定数列里两两异或值为x的组合个数
    • 暴力n方,会超时
    • 根据异或运算性质:a^b=x; x^a=b; x^b=a;
    • 所以可以直接O(n)的遍历每一个数,查找x异或这个数是否存在即可

    std:

    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    const int maxn = 1e6 + 10;
    int a[maxn],sum[maxn];
    int main()
    {
        int n,x,y,z;
        ll ans = 0;
        cin>>n>>x;
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n;i++){
            z = x^a[i];
            if(sum[z])
                ans += 1ll*sum[z];
            sum[a[i]]++;
        }
        cout<<ans<<endl;
        return 0;
    }
    
  • 相关阅读:
    springMvc
    计算机网络
    Mybatis 总结
    Spring 面试总结
    Java IO 流
    自定义类加载器
    缓存一致性协议
    dfs、bfs序
    7.26
    Trick
  • 原文地址:https://www.cnblogs.com/QFNU-ACM/p/12603321.html
Copyright © 2011-2022 走看看