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;}
- Codeforces 868 C Qualification Rounds
- codeforces 868C Qualification Rounds
- codeforces 868C Qualification Rounds
- Codeforces 868C Qualification Rounds
- Codeforces 868C Qualification Rounds
- CodeForces 868C Qualification Rounds
- codeforces 868C Qualification Rounds
- Codeforces 868 C. Qualification Rounds (技巧)
- Codeforces 868C Qualification Rounds【思维】
- Codeforces 868C Qualification Rounds 结论
- Codeforces round438 C. Qualification Rounds
- codeforces 868C.Qualification Rounds(bitmasks与状压dp)
- Codeforces Round #438 C. Qualification Rounds
- Codeforces Round #438 C. Qualification Rounds 二进制
- codeforces round #438 C. Qualification Rounds
- Codeforces Round #438 C. Qualification Rounds 题解
- Codeforces Round #438 C. Qualification Rounds
- CF 868 C. Qualification Rounds 【状态压缩】
- rocketmq双Master集群模式搭建
- eclipse开发webservice服务
- C和C++字符串删除等特定操作处理
- Vision_字符串_AC自动机
- BOS系统的设计与实现
- codeforces 868C Qualification Rounds
- 8. 适配器模式
- Codeforces Round #439 A The Artful Expedient 博弈解释 +暴力写法
- 二分查找
- Hibernate的持久化对象状态
- python里使用正则的finditer()函数
- mysql服务器无法连接10055错误解决示例
- FTPrep, 106 Construct Binary Tree from Inorder and Postorder Traversal
- JAVA提高篇(17)--打印流PrintStream记录日志文件