codeforces 868c(二进制)
来源:互联网 发布:js半圆形仪表盘 编辑:程序博客网 时间:2024/06/01 10:55
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of nproblems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems.
Determine if Snark and Philip can make an interesting problemset!
The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.
Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
5 31 0 11 1 01 0 01 0 01 0 0
NO
3 21 01 10 1
YES
思路:如果能选出几题满足,那么必定可以选出2题的情况满足。这样使用2进制表示每道题几个队伍的知道情况,这样这道题的情况就变成了一个小于16的数,知道找到两道题的情况&运算为0即可。
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;bool data[16];int main(){int n,k;int x;while(~scanf("%d%d",&n,&k)){for(int i=0;i<n;i++){int cnt=0;for(int j=0;j<k;j++){scanf("%d",&x);cnt*=2;cnt+=x;}data[cnt]=1;}bool flag=false;for(int i=0;i<16;i++){int j;for(j=0;j<16;j++){if(((i&j)==0)&&data[i]&&data[j]){flag=true;break;}}if(j<16)break;}if(flag)printf("YES\n");else printf("NO\n");}}
- codeforces 868c(二进制)
- 二进制 模拟 codeforces 485C
- Codeforces #317(div.2) C(二进制 状压)
- Codeforces 677C Vanya and Label(二进制)
- Codeforces Round #438 C. Qualification Rounds 二进制
- C. Amr and Chemistry(Codeforces Round #312 (Div. 2) 二进制+暴力)
- Codeforces 309C Memory for Arrays 二进制模拟进位
- Codeforces Round #276 (Div. 2) C. Bits 二进制
- C+++二进制信号量(1)
- Codeforces 868 C. Qualification Rounds (技巧)
- Codeforces-868C
- codeforces 868C
- Codeforces 868C
- Codeforces Beta Round #96 (Div. 2) (二进制数取模)
- codeforces-#476B. Dreamoon and WiFi(dfs、二进制枚举)
- COdeforces 835E The penguin's game (二进制)
- codeforces 121 (比赛) codeforces 191C
- codefoces 868C(二进制,状态压缩)
- work1
- 第五周项目1
- 关于异常“Error:Conflict with dependency 'com.google.code.findbugs:jsr305'”
- webview接入HttpDNS实践
- 赛后反思
- codeforces 868c(二进制)
- 多媒体会议混音算法
- 新建一个Observable,返回observable对象
- 用户权限管理模块的数据库设计
- 【第三周】项目3-求集合并集
- 如何通过ABBYY FineReader实现JPEG到Excel的转换
- 文件读操作
- 2018校招-阿里巴巴测试开发工程师面试经验
- Keras.layers.core.dense()方法详解