CodeFroces Round 438C. Qualification Rounds(思维题)

题意:给出n个题目,k个队伍是否刷过这题的情况表。现在要举办一场比赛,要求用的题目,不能有队伍已经刷过一半以上。问是否存在解。

解法:当时瞎写发现,好像只要选两个就可以了,然后就开始猜结论来写。由于k只有4,所以说最多只有1<<4种情况。直接转为二进制,暴力一下即可。

代码如下:

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<utility>
#include<stack>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<map>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], n, k;
bool vst[maxn];

int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++) {
		int t = 0;
		for(int j = 0; j < k; j++) {
			int tmp;
			scanf("%d", &tmp); 
			if (!tmp) {
				continue;
			}
            t |= (1 << j);
		}
		vst[t] = 1;
	}
	bool flag = 0;
	for(int i = 0; i < (1 << k); i++) {
		for(int j = i; j < (1 << k); j++) {
			if(!vst[i] || !vst[j])
				continue;
			if((i & j) == 0) {
				flag = 1;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值