当前位置: 代码迷 >> 综合 >> codeforces742B Arpa’s obvious problem and Mehrdad’s terrible solution(水)
  详细解决方案

codeforces742B Arpa’s obvious problem and Mehrdad’s terrible solution(水)

热度:31   发布时间:2024-01-16 13:27:32.0

题意:

给出一系列数字,求两两异或为x有几对。

要点:

看范围10^5就知道直接循环肯定gg,所以用一个num[x]存储x出现过几次,一般用两个for可以简化,像下面这样:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 9000500;
int a[N];
//map<int, int> num;
int num[N];int main()
{int n, x;scanf("%d%d", &n, &x);for (int i = 0; i < n; i++)scanf("%d", &a[i]);ll count = 0;for (int i = 0; i < n; i++){if (num[x^a[i]])count += num[x^a[i]];num[a[i]]++;			//这一步达到了两个for的作用,等于只能计算当前数前面的}printf("%I64d\n", count);return 0;
}


  相关解决方案