传送门:https://codeforces.com/problemset/problem/1395/C
题意

思路
根据题意看出,ans最大只有$2^9(512)$,所以我们可以枚举答案。 对于一个ans,如果所有的$a_i$都可以找到$b_j$,使得$ans(a_i\&b_j)=ans$,则最小答案为ans.
因为从0枚举到512,所以存在答案时总是最小的。
复杂度:$O(2^9*n*m)$
Code(31MS)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| ##include "bits/stdc++.h" using namespace std;
typedef long long ll;
void solve() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for(int i = 0;i < n; i++) cin >> a[i]; for(int i = 0;i < m; i++) cin >> b[i]; for(int ans = 0;ans <= (1 << 9); ans++) { bool f = 0; for(int i = 0;i < n; i++) { bool flag = 0; for(int j = 0;j < m; j++) { int temp = a[i] & b[j]; if((ans temp) == ans) flag = 1; if(flag) break; } if(!flag) break; if(i == n - 1 && flag) f = 1; } if(f) { cout << ans << endl; return ; } } }
signed main() { solve(); }
|
本文作者:jujimeizuo
本文地址: https://blog.jujimeizuo.cn/2021/03/24/codeforces-round-664-div-2-c/
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0 协议。转载请注明出处!