Codeforces Round #664 (Div. 2) C

害,这个题目被hack掉了,真难受啊,害的我掉了60多分,菜鸡如我到现在还没有上蓝,我太菜了。
这个题目的做法就是暴力枚举,首先得预处理出每个ai和每个bi&的值,然后就开始暴力枚举答案从0到(1<<9);如果满足题意就输出一定是最小的。为什么可以枚举呢?假设a|b=c那么c>=a&&c>=b,所以如果枚举的答案是k那么k|ci<=k

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x & -x
#define fi first
#define ull unsigned long long
#define se second
#define lson (rt<<1)
#define rson (rt<<1|1)
#define endl "\n"
#define bug cout<<"----acac----"<
#define IOS ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
using namespace std;
const int maxn = 4e4 + 10;
const int maxm = 1.5e5 + 50;
const double eps = 1e-18;
const double inf = 0x3f3f3f3f;
const ll  lnf = 0x3f3f3f3f3f3f3f3f;
const int mod = 80112002;
const  double pi = 3.141592653589;
int a[205], b[205], c[205][205];
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= m; i++)
	{
		scanf("%d", &b[i]);
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			c[i][j] = a[i] & b[j];
		}
	}
	for (int k = 0; k <= (1 << 9); k++)
	{
		bool flage = 0;
		int cnt = 0;
		for (int i = 1; i <= n; i++)
		{
			flage = 0;
			for (int j = 1; j <= m; j++)
			{
				if ((k | c[i][j]) <= k)
				{
					flage = 1;
				}
			}
			cnt += flage;
		}
		if (cnt == n)
		{
			printf("%d\n", k);
			return 0;
		}
	}
	return 0;
}


你可能感兴趣的:(acm暑训,codeforces)