Codeforces Round #383 (Div. 2) B(打表)
来源:互联网 发布:剑网三咩太捏脸数据 编辑:程序博客网 时间:2024/06/15 10:53
题目链接
题目意思,有n个数求n个数取两个数有多少个这样的组合抑或值等于k
因为 a^b=k且 a^k=b;
所以我们可以先打出跟k抑或后的结果表,然后通过查表输出答案
#include<stdio.h>#include<string.h>#include<map>using namespace std;long long a[200010];long long b[200010];long long c[200010];int main(){ long long n,k; scanf("%lld%lld",&n,&k); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); for(int i=1;i<=131072;i++) { a[i]=i^k; } int cut=0; for(int i=0;i<n;i++) { int q; scanf("%d",&q); if(!b[q]) c[cut++]=q; b[q]++; } long long ans=0; for(int i=0;i<cut;i++) { ans+=b[c[i]]*b[a[c[i]]]; } if(k==0) //0抑或后等于自己本身所以要特判一下,当然也可以结合到上面去 { ans=0; for(int i=0;i<cut;i++) { ans+=b[c[i]]*(b[c[i]]-1); } } printf("%lld\n",ans/2);}
0 0
- Codeforces Round #383 (Div. 2) B(打表)
- Codeforces Round #277 (Div. 2)(A)模拟,打表
- Codeforces Round #383 (Div. 2)(A+B)
- Codeforces Round #383 (Div. 2) B
- Codeforces Round #383 (Div. 2) B
- Codeforces Round #256 (Div. 2)(B)
- Codeforces Round #350 (Div. 2)(B)
- Codeforces Round #379 (Div. 2)B
- 【Codeforces Round #383 (Div. 2)】 (A,B,C)
- Codeforces Round #269 (Div. 2) C 递推+打表
- 【打CF,学算法——二星级】Codeforces Round #313 (Div. 2) B. Gerald is into Art(水题)
- 【Codeforces Round #327 (Div. 2) B】 Rebranding 字符变换 同类型打标记
- Codeforces Round #355 (Div. 2) C. Vanya and Label (打表+字符串)
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game (打表)
- Codeforces Round #383 (Div. 2) && Codeforces 742 B (标记技巧)
- Codeforces Round #383 (Div. 2) B, C, D
- Codeforces Round #383 (Div. 1) B
- B. Inventory(Codeforces Round #315 (Div. 2)水题)
- 数据库的索引和数据库查询
- 增量更新(制作差分包笔记)
- Unity3D在mac上使用VSCODE开发
- 备忘录模式(行为类)
- 今天12.7日,卖了氯霉素眼药水
- Codeforces Round #383 (Div. 2) B(打表)
- Serv-U FTP Server 中文版 11.0.0.4安装及使用说明
- I2C笔记
- html标签被当成文本
- 存储过程增删改查
- Android Studio连接Genymotion模拟器
- 有其他mysql存在的情况下,MAC-XAMPP的mysql无法启动的解决方案
- 算法练习3:Playing with digits
- 【Swoole】当SWOOLE遇上PHP