Codeforces-868C
来源:互联网 发布:java中的foreach循环 编辑:程序博客网 时间:2024/06/06 03:13
链接:
http://codeforces.com/contest/868/problem/C
题目:
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个队,1代表这个队伍知道这道题的答案,0代表不知道。问你能否调出若干个题,使得每只队伍知道的答案数目不多于调出来的题目的数目的一半。
思路:
可以看到k很小,对于每个问题,可以通过每个队伍知不知道这道题的情况来将这类题目唯一化,所以总共有16种可能,用二进制记录一下然后寻找满足题目的情况即可。
实现:
#include <cstdio>int book[27], n, k, tmp, t;int main() { scanf("%d%d", &n, &k); while(tmp = 0, n--) { for(int j=0 ; j<k ; j++) scanf("%d", &t), tmp |= (t<<j); book[tmp]++; } for(int i=0 ; i<16 ; i++) for(int j=0 ; j<16 ; j++) if(i&j == 0 && book[i] && book[j]) return 0*printf("YES\n"); printf("NO\n"); return 0;}
- Codeforces-868C
- codeforces 868C
- Codeforces 868C
- 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 868c(二进制)
- Codeforces 868 C. Qualification Rounds (技巧)
- Codeforces Round #438 868A/B/C
- Codeforces 868C Qualification Rounds【思维】
- Codeforces 868C Qualification Rounds 结论
- Codeforces-868B ,C 模拟,思维。。
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- WindowsError的错误代码详解
- UVALive 7272 Promotions【拓扑排序】【bitset】
- Eclipse 修改背景图片(不是修改背景颜色)
- cartogarpher slam 3
- python实现最小二乘法(转)
- Codeforces-868C
- R programming羊羊学习笔记
- Hadoop生态系统介绍
- 数据结构——顺序表互换之逆置算法
- 【Algorithms】最短路径算法CH:Contraction hierarchies
- 机器学习 第二周 总结 知识点
- 2017.10.5 自己的第一篇博客文章~
- 一张图入门python
- python网络数据采集学习范例—利用CSS爬取网站特定标签,BeautifulSoup函数介绍及子标签