文章Educational Codeforces Round 134 D,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
D. Maximum AND
可以很轻松通过^和& 两个操作看出 我们要求的两个序列每一位上的1加起来必须等于n才行
多一个少一个都不行
然后1加起来等于n 0自然加起来也等于n 0和1的数量相等
但是直接每一位算肯定是不对的 因为会有有些组不同 比如样例1
我们考虑按位贪心 让后面的组要是和前面组符合 那么加入即可
这里就可以用map 要是后面的组符合前面的组 那么我们就算加上了1<#include using namespace std;const int N = 1e5+10;const int M = 998244353;const int mod = 1000000007;#define int long long#define endl '\n'#define Endl '\n'#define YES cout<<"YES"<> n; vector a(n), b(n); for (int i = 0; i < n; i++)cin >> a[i]; for (int i = 0; i < n; i++)cin >> b[i]; int c = 0; for (int j = 29; j >= 0; j--) { map mp; c += 1 << j; for (int i = 0; i < n; i++) { mp[a[i] & c]++; mp[~b[i] & c]--; } bool flag = true; for (auto i: mp) { if (i.second != 0) { flag = false; break; } } if (!flag) c -= (1 << j); } cout << c << endl;}signed main(){ fast int T;cin>>T; while(T--) { solve(); } return ~~(0^_^0);}
1. 本站所有资源来源于用户上传或网络,仅作为参考研究使用,如有侵权请邮件联系站长!
2. 本站积分货币获取途径以及用途的解读,想在本站混的好,请务必认真阅读!
3. 本站强烈打击盗版/破解等有损他人权益和违法作为,请各位会员支持正版!
4.
编程技术 > 教育 Codeforces 第 134 轮 D