1 条题解
-
0
利用
bitset
进行位运算优化即可,时间复杂度为。 代码中判断子集时运用了的技巧。#include <iostream> #include <bitset> using namespace std; bitset<64> a, b, c; int m, n; void print(bitset<64> bs) { for (int i = 0; i < 64; ++i) if (bs[i]) cout << i << ' '; cout << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> m; for (int i = 1; i <= m; ++i){ int x; cin >> x; a[x] = true; } cin >> n; for (int i = 1; i <= n; ++i) { int x; cin >> x; b[x] = true; } cout << m << endl; c = a & b; print(c); print(a | b); print(~a); cout << (a == b) << endl; cout << (a == c) << endl; cout << a[0] << endl; return 0; }
- 1
信息
- ID
- 7499
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 3
- 标签
- 递交数
- 2
- 已通过
- 2
- 上传者