思路:

枚举尝试即可,参考了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 }

相关文章:

  • 2022-12-23
  • 2022-01-12
  • 2021-04-29
  • 2021-07-19
  • 2022-02-14
  • 2022-12-23
  • 2022-01-10
  • 2021-09-12
猜你喜欢
  • 2021-10-10
  • 2021-10-03
  • 2021-10-13
  • 2021-07-01
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案