Codeforces 724B
来源:互联网 发布:ubuntu anaconda安装 编辑:程序博客网 时间:2024/06/01 08:42
题意:给定一个数组和一个x,求数组中能异或得到x的对数。
解法:a^b=x等价于a^x=b,因为数组中的数只有10^5,所以可以将每个数放到对应的num数组中。答案就是每个num[a]*num[a^x]之和。开始以为不能重复,求的是min(num[a],num[a^x])之和。随后被hack,比赛完发现没有特判0。当x等于0时,a^0=a,求的是C(num[a],2)之和。
#include <bits/stdc++.h>using namespace std;const int maxn = 200000+10;int n,x,t,vis[maxn];long long a[maxn],res;int main(){// freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&x)!=EOF) { memset(a,0,sizeof(a)); memset(vis,0,sizeof(vis)); res=0; for(int i=0;i<n;i++) { scanf("%d",&t); a[t]++; } for(int i=1;i<=100000;i++) { if(x==0) { res+=a[i]*(a[i]-1)/2; } else if(!vis[i]&&!vis[i^x]) { res+=a[i]*a[i^x]; vis[i]=1; vis[i^x]=1; } } cout<<res<<endl; } return 0;}
0 0
- Codeforces 724B
- Codeforces 724B 暴力模拟
- codeforces 724B 暴力+枚举
- codeforces 724B Batch Sort
- codeforces 724B Batch Sort
- CodeForces 724B Batch Sort
- CodeForces 724B BatchSort 暴力
- CodeForces 724B(暴力枚举)
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- 【39.77%】【codeforces 724B】Batch Sort
- Codeforces 724B Batch Sort(暴力枚举)
- Codeforces 724B Batch Sort【暴力枚举】
- 【codeforces 724B Batch Sort】+ 枚举
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- 动态代理
- C++ P1726 上白泽慧音
- jquery操作大全筛选dom事件动画表单等
- 半透明渲染新技术摘录
- ThreadUtils
- Codeforces 724B
- 2017年微商方向选择
- Spring加载加密后的文件,防止反编译
- 利用AJAX重写,解决session超时,ajax跳转问题
- 稳定排序和不稳定排序
- ACCP C#Windows 第三章课后5
- 盒子模型
- Android结构
- 编译+反编译+去掉jd-gui行号