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<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<deque>
#include<map>
#include<stdlib.h>
#include<set>
#include<iomanip>
#include<stack>
#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----"<<endl
#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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值