CodeForces 272B
2013-07-21 13:49
204 查看
2*a 相当将a的二进制中的数左移一个位置,末尾加0; 2*a 相当将2*a的末尾加1,2*a的末尾一定是0; f[x] 就是计算x的二进制1的个数; #include <iostream> #include <cstdio> using namespace std; int main() { int t; cin >> t; int f[100]= {0}; while(t--) { int n; cin >> n; int tot = __builtin_popcount(n);//计算二进制中有多少个1 f[tot]++; } long long ans = 0; for(int i = 1; i <= 32; i++) ans +=(long long)f[i]*(f[i]-1)/2; cout << ans << endl; }
相关文章推荐
- CODEFORCES 272B Dima and Sequence <简单技巧 + 类比奇偶数>
- CodeForces 272B
- CodeForces - 272B Dima and Sequence 函数/思维
- Codeforces 442C Artem and Array(stack+贪心)
- codeforces 583 D. Once Again... (LIS + 贪心)
- CodeForces 659D Bicycle Race (判断点是否为危险点)
- python爬虫抓取codeforces分数
- codeforces——432A—— Choosing Teams
- Codeforces 877 C. Slava and tanks
- CodeForces 52C Circular RMQ (区间更新线段树)
- Codeforces 584 B. Kolya and Tanya (Codeforces Round #324 (Div. 2))
- Codeforces-Round-#357-(Div.-2)-A-Good-Contest
- codeforces 732B The Best Friend Of a Man 贪心
- 【水题】CodeForces - 233A Perfect Permutation
- codeforces 883H Palindromic Cut
- Codeforces 444C DZY Loves Colors 水线段树
- Codeforces 584E Anton and Ira
- codeforces 682D(Alyona and Strings)
- Codeforces 734E 树的直径+缩点
- 二分 Tavas and Karafs:CodeForces 535C