Codeforces round #664C

Codeforces round #664C

纪念第一次熬夜打cf还有第一次补题写题解
然而本文还是比较水

Boboniu Chats with Du (CodeForces - 1394A)

比赛题目链接
对应的vj题目链接

题意:

Boboniu and Bit Operations

(time limit per test1 second)
(memory limit per test256 megabytes)

Boboniu likes bit operations. He wants to play a game with you.

Boboniu gives you two sequences of non-negative integers a1,a2,…,an and b1,b2,…,bm.

For each i (1≤i≤n), you’re asked to choose a j (1≤j≤m) and let ci=ai&bj, where & denotes the bitwise AND operation. Note that you can pick the same j for different i’s.

Find the minimum possible c1|c2|…|cn, where | denotes the bitwise OR operation.

Input
The first line contains two integers n and m (1≤n,m≤200).

The next line contains n integers a1,a2,…,an (0≤ai<29).

The next line contains m integers b1,b2,…,bm (0≤bi<29).

Output
Print one integer: the minimum possible c1|c2|…|cn.

比赛的时候看到这道题感觉和或和与的性质有关啥的,还想着有没有交换律(并没有)结果就跑偏了。(感觉一看到这种按位操作的题不管是博弈也好贪心也好都比较怵)

官方题解

感觉这个题解思路还是很暴力的

官方代码

#include<bits/stdc++.h>
#define ci const int&
using namespace std;
int n,m,p[210],d[210],ans;
bool Check(ci x){
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)if(((p[i]&d[j])|x)==x)goto Next;
		return 0;
		Next:;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&p[i]);
	for(int i=1;i<=m;++i)scanf("%d",&d[i]);
	ans=(1<<9)-1;
	for(int i=8;i>=0;--i)Check(ans^(1<<i))?ans^=(1<<i):0;
	printf("%d",ans);
	return 0;
}
由于看不懂题解只能自己写一发朴素易懂的代码
//codeforces1395C
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <cstdio>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=200+5;
int n,m,a[maxn],b[maxn],ans;

bool Check(int x){
	for(int i=1;i<=n;i++){
		bool flag=0;
		for(int j=1;j<=m;j++){
			if(((a[i]&b[j])|x)==x) {
				flag=1;
				break;
			}
		}
		if(flag) continue;
		return 0;
	}
	//官方代码 
//	for(int i=1;i<=n;++i){
//		for(int j=1;j<=m;++j)if(((a[i]&b[j])|x)==x)goto Next;
//		return 0;
//		Next:;
//	}
	return 1;
}

int main(){
	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]);
	//官方代码 
//	ans=(1<<9)-1;
//	for(int i=8;i>=0;i--) Check(ans^(1<<i))?ans^=(1<<i):0;
	for(int i=0;i<=(1<<9)-1;i++){
		if(Check(i)){
			ans=i;
			break;
		}
	}
	printf("%d",ans);
}
水完了第一篇博客?连我自己都觉得水。。。没办法一会下午还要学车只能凑合了(逃)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值