icpc:problems:absolute_maximization
problems | |
---|---|
名称 | Absolute Maximization |
题目编号 | 840A |
题目链接 | codeforces.com/… |
来源 | CodeForces |
算法分类 | 位运算, 贪心 |
难易程度 | 容易 |
Absolute Maximization
想法
对每个二进制位建桶,如果某一位不是所有数均出现,那这一位就可以相减在答案中。
代码实现
#include<iostream> #include<cstring> using namespace std; int line[530]; int tong[15]; int main() { int T; cin >> T; while(T--) { memset(tong, 0, sizeof(tong)); int n; cin >> n; for(int i=1; i<=n; ++i) cin >> line[i]; for(int i=1; i<=n; ++i) { for(int j=1; j<=10 && line[i]; ++j, line[i]>>=1) if(line[i]&1) tong[j]++; } int ans = 0, temp = 1; for(int i=1; i<=10; ++i) { if(tong[i] != n && tong[i] != 0) ans += temp; temp <<= 1; } cout << ans << endl; } return 0; }
/app/www/public/data/pages/icpc/problems/absolute_maximization.txt · 最后更改: 2023/09/30 07:28 由 温婕莺