codeforces 868C Qualification Rounds

来源:互联网 发布:分类汇总数据复制出来 编辑:程序博客网 时间:2024/05/21 04:17

C. Qualification Rounds
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, 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!

Input
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.

Output
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”).

Examples
input
5 3
1 0 1
1 1 0
1 0 0
1 0 0
1 0 0
output
NO
input
3 2
1 0
1 1
0 1
output
YES
Note
In the first example you can’t make any interesting problemset, because the first team knows all problems.

In the second example you can choose the first and the third problems.

题意:有n道问题,有k个队伍,每道题目有些队伍做过。问你能不能从n道题目中选出任意道题目举办一场比赛,要求在这场比赛中任何一个队伍做过的题目都不超过一半

思路: 对于n == 1时,只要这道题目别人都没有做过,就可以。其他的只要找到两个题目符合对应位置不全为1就可以。比如一道题目1001,即AD两只队伍会做,只要再找到一个题目AD两个队伍都不会做就可以了,如0100,所以,我们只要枚举每一道题目,如果能然后把其对应的放到set里面,如果下次能找到对应的题目就跳出。如某道题目为1101,就把对应的0000,0010,放到set里面,如果有道题目是这两个其中的一个,就是符合的。

代码如下:

#include<iostream>#include<cstdio>#include<cstring>#include<set>#include<map>#include<vector>#include<algorithm>#include<cmath>using namespace std;typedef long long ll;const int MAX = 100010;set<int> st;set<int>::iterator it;int n,k;int q[MAX];void get(int x){    int M = pow(2,k)-1;    for(int i=0;i<M;++i){        if((i&x) == 0)            st.insert(i);    }}bool solve(){    if(n == 1 && q[1] == 0) return true;    for(int i=1;i<=n;++i){        it = st.find(q[i]);        if(it == st.end()){            get(q[i]);        }        else            return true;    }    return false;}int main(void){    int x;    scanf("%d %d",&n,&k);    for(int i=1;i<=n;++i){        int res = 0;        for(int j=1;j<=k;++j){            scanf("%d",&x);            res = res*2 + x;        }        q[i] = res;    }    if(solve())        printf("YES\n");    else        printf("NO\n");    return 0;}
原创粉丝点击