codeforce868c
2 seconds
256 megabytes
standard input
standard output
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 3
1 0 1
1 1 0
1 0 0
1 0 0
1 0 0
NO
3 2
1 0
1 1
0 1
YES
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个题,m个人,从n个题中挑k道题,使m个人每个人会的题目数不超过k/2。
输入的意思是:第i行第j列为1,说明第j个人会第i道题,为0说明不会
结论:k直接取2就行 取大了反倒不好满足
首先我们先分成两种情况
k = 1 就看有没有全0行嘛,对吧
k >= 2 首先考虑p道题满足的情况下的,首先p道题我们就确定这已经是一个稳定的系统了,那么我们再加一行,这一行肯定有至少一个1(否则这道题全是0,就是第一种情况了),p加一行的话肯定某一个人会多对一道题,意思就是,其它人的正确率会下降,但是不会导致p+1这个集合变得不符合题意,但是加1的那一列却有可能导致集合不符合题意。
所以,直接取k = 2即可,在k=2上面加题反倒可能会使集合可能坏掉
其次说一下具体实现,一共就最多4个人,一道题,最多也就是2的4次方,16种排列。直接枚举每一种即可,
用一个ans[16]表示每种情况出现过几次,在输入的时候就能够处理
附上代码
#include <iostream>
using namespace std;
int arr[16] = {0};
int main()
{
int n,m,i,j,t,temp;
cin >> n >> m;
for(i = 0; i < n; ++i)
{
temp = 0;
for(j = 0; j < m; ++j)
{
scanf("%d",&t);
temp |= t<<j;
}
arr[temp]++;
}
for(i = 0;i < 16; ++i)
{
for(j = 0; j < 16; ++j)
{
if((i&j) == 0 && arr[i] && arr[j])
{
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
}
codeforce868c的更多相关文章
随机推荐
- DOM心得
一.自定义属性值两种方法的注意事项 1.用元素节点.属性(元素节点[属性])绑定的属性值不会出现在标签上. 2.用get/set/removeAttribut(,)等绑定的属性会出现在标签上.且两种方 ...
- PAT 1046 划拳(15)(代码)
1046 划拳(15)(15 分) 划拳是古老中国酒文化的一个有趣的组成部分.酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字.如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢 ...
- Linux系统性能监控工具介绍之-tsar
Linux系统性能监控工具介绍之-tsar Linux系统性能监控工具介绍之-tsar 2017-03-02 20:25 175人阅读 评论(0) 收藏 举报 分类: LINUX调优(9) 目 ...
- Android.Study.Question
1. NullPointerException 1.1 发生该异常的原因. 1.2 解决方法有哪几种? try-catch 2. Eclipse 中 debug/run 两个模式,run 是relea ...
- 探索未知种族之osg类生物---起源
任何程序都是有生命的,是生命就需要呼吸.例如普通的windows程序,当运行完main()函数后,就需要进入消息循环,来监听用户的各种操作,以便做出及时的回应.这样的每次循环就像生命的每次呼吸,来维持 ...
- linux网卡绑定脚本
2013-08-20 15:30:51 此脚本适用于CentOS5.x和CentOS6.x. #!/bin/bash #**************************************** ...
- hisat2+stringtie+ballgown
hisat2+stringtie+ballgown Posted on 2016年11月25日 早在去年九月,我就写个博文说 RNA-seq流程需要进化啦!http://www.bio-info-tr ...
- 存储过程和函数 PROCEDURE & FUNCTION
SQL语句执行的时候,要首先编译,然后在被执行.在大型数据库系统中,为了提高效率,将为了完成特定功能的SQL语句集进行编译优化后,存储在数据库服务器中,用户通过指定存储过程的名字来调用执行. 具体而言 ...
- linux 虚拟机设置
1.可以用网桥方式 2.可以用一个回环虚拟网卡即可.
- Django 自定义模板标签TemplateTags
创建自定义的模板标签(template tags) Django提供了以下帮助函数(functions)来允许你以一种简单的方式创建自己的模板标签(template tags): simple_tag ...