Codeforces Gym 101484 K Counting Good Teams
来源:互联网 发布:数据表格共享平台 编辑:程序博客网 时间:2024/05/06 19:15
原题链接:
http://codeforces.com/gym/101484/problem/K
题意:
N个人,任选两个人组队,每个人有一个代表自己能力的二进制数值xi(输入中以十进制数的形式给出),如果两个人的二进制表示中都至少有一位,自己是1,对方是0,则这两个人可以组成一个good team,题目问有多少组good team。数据范围(N <= 1e5, xi < 2 ^ M, M <= 21)
分析:
按位统计
由题意显然可得,一个good team的两个成员i, j,(xi | xj) > xi && (xi | xj) > xj ,我们考虑相反的情况,即 (xi | xj) == max(xi, xj)。所以,我们只要枚举每个数xi,统计有多少满足(xj <= xi && xj | xi == xi)的数。
代码:
#include <bits/stdc++.h>using namespace std;const int maxn = 2100000 + 50;long long cnt[maxn], dn[maxn];int main(){ int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); cnt[x]++; dn[x]++; } for (int i = 0; i < m; ++i) { for (int j = 0; j < (1 << m); ++j) { if ((j & (1 << i)) == 0) continue; dn[j] += dn[j ^ (1 << i)]; } } long long ans = (long long)(n - 1) * (long long)n / 2LL; for (int i = 0; i < (1 << m); ++i) { ans -= cnt[i] * dn[i] - (cnt[i] * (cnt[i] + 1) / 2); } cout << ans << endl; return 0;}
阅读全文
0 0
- Codeforces Gym 101484 K Counting Good Teams
- codeforces [Gym-100814K]
- Codeforces gym 101149 K 想法
- Codeforces gym 101102 K 想法
- codeforces Gym 101341 K Competitions
- Longest k-Good Segment CodeForces
- Teams Gym-101028E
- Codeforces Gym 100792K King's Rout
- Codeforces Gym 101142 K. King's Heir
- Codeforces Gym 100971M Decomposition into Good Strings DP+数据结构
- codeforces 616D Longest k-Good Segment
- codeforces 616D Longest k-Good Segment
- Codeforces 616 D. Longest k-Good Segment
- codeforces 616D Longest k-Good Segment
- CodeForces 616D Longest k-Good Segment
- codeforces Longest k-Good Segment 616D
- CodeForces 616D Longest k-Good Segment
- Codeforces 616D Longest k-Good Segment
- 永远追不上的人?
- fragment不会保留最后一个
- Spring Batch 在大型企业中的最佳实践
- [ACM模板]manacher算法(回文串统计)
- CC2640芯片简介
- Codeforces Gym 101484 K Counting Good Teams
- 数据结构实验之栈与队列三:后缀式求值
- 丑数--python实现
- Fatal error: Maximum function nesting level of '256' reached, aborting!
- SSD: Single Shot MultiBox Detector 论文笔记
- Java下载Excel文件
- SpringMVC源码解析(四)之关于json,xml的自动转换原理
- CPU缓存鸟瞰
- string操作