码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-07-19 14:41:42      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:span   size   blog   代码   pac   style   反向   nbsp   clu   

假期训练的一道题,用了一些异或的一些性质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 }

 

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

标签:span   size   blog   代码   pac   style   反向   nbsp   clu   

原文地址:http://www.cnblogs.com/lalalatianlalu/p/7205041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!