CodeForces - 742B Arpa’s obvious problem and Mehrdad’s terrible solution

假期训练的一道题,用了一些异或的一些性质1^2=3,3^1=2,3^2=1

就是相当于反向异或运算然后查找个数。

提供一组样例

5 0

1 1 1 1 1

这就是用long long的原因

下面是代码

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e6+5;
 4 typedef long long ll;
 5 int b[maxn], n, x;
 6 
 7 int main()
 8 {
 9     while(~scanf("%d %d",&n,&x))
10     {
11         memset(b, 0, sizeof(b));
12         ll ans = 0;
13         for(int i = 1; i <= n; i++)
14         {
15             int a;
16             scanf("%d", &a);
17             ans += b[a^x];
18             b[a]++;
19         }
20         printf("%lld\n", ans);
21     }
22     return 0;
23 }

 

posted @ 2017-07-19 12:00  啦啦啦天啦噜  阅读(176)  评论(0编辑  收藏  举报