Qualification Rounds
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
题意:有n道题,k个队伍。已知这些队伍认识的题目。现在要你定制一个比赛,要求比赛中的题目每个队认识的不能超过一半,问是否可能。
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 1000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e5+10;
const double eps=1e-6;
int n,k;
int vis[20];
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
int juge=0;
cin>>n>>k;
for(int i=1;i<=n;i++){
int t,temp=0;
for(int j=1;j<=k;j++){
scanf("%d",&t);
if(t)
temp+=pow(2,j-1);
}
vis[temp]=1;
}
for(int i=0;i<=16;i++){
for(int j=0;j<=16;j++){
if(!(i&j)&&vis[i]&&vis[j])
juge=1;
}
}
if(juge)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}
探讨了如何为有经验的参赛团队设计合理的比赛问题集。在比赛中,每支队伍已知的题目不能超过所选题目的半数。通过算法判断是否能创建一个满足条件的问题集合。
3万+

被折叠的 条评论
为什么被折叠?



