思路:
枚举尝试即可,参考了http://codeforces.com/blog/entry/81355。
实现:
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int N = 205; 5 int a[N], b[N], n, m; 6 7 bool check(int x) 8 { 9 for (int i = 0; i < n; i++) 10 { 11 bool flg = false; 12 for (int j = 0; j < m; j++) 13 { 14 int tmp = a[i] & b[j]; 15 if ((tmp | x) == x) { flg = true; break; } 16 } 17 if (!flg) return false; 18 } 19 return true; 20 } 21 22 int main() 23 { 24 while (cin >> n >> m) 25 { 26 for (int i = 0; i < n; i++) cin >> a[i]; 27 for (int j = 0; j < m; j++) cin >> b[j]; 28 int res = 1 << 9; 29 for (int i = 0; i < 1 << 9; i++) 30 { 31 if (check(i)) { res = i; break; } 32 } 33 cout << res << endl; 34 } 35 return 0; 36 }