C. Qualification Rounds
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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!

Input

The first line contains two integers nk (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个题,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的更多相关文章

随机推荐

  1. 1S - 平方和与立方和

    给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和.  Input 输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成. Output 对于每组输入数据,输出一行,应 ...

  2. Tinyos学习笔记(三)

    读取Telosb内部传感器数据,并在计算机上显示. senseC.nc代码如下: #include "Timer.h" #include "sense.h" # ...

  3. A面&B面

    难难难.道是玄,不遇知音不可谈.遇了知音聊两句,免教那枉费舌尖.难得今天心情不错,反思毕业这五年的种种,有浑噩.迷茫.彷徨.莽撞.执着.困顿.不惧,走到今天迈过了几道坎早已忘却,同时也还在询问自己值不 ...

  4. android xml 解析汉字只出来一个字的问题

    DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); // 实例化DocumentBuilder factor ...

  5. ubuntu下为单个网卡配置多个ip

    参考文档: https://www.jb51.net/os/Ubuntu/418951.html https://blog.csdn.net/ying1989920/article/details/4 ...

  6. java 环境搭建

    一.安装jdk 下载jdk http://www.oracle.com/technetwork/java/javase/downloads 将下载的jdk文件放到 /opt 下解压 $sudo cp ...

  7. django模板语言和过滤

    一:模板组成 HTML代码 + 逻辑控制代码 逻辑代码组成格式: 使用大括号来引用变量, {{ var_name }} 二: Template和Context对象 //进入该的django的项目环境 ...

  8. [SoapUI] 从Map里面不想要的键值对

    def keysToRemoveForBoss = ["RequestIdBmk", "RequestIdTest"] def extraInfoMapForB ...

  9. PHP redis 群发短信

    $redis = new \Redis(); $redis->connect('127.0.0.1', 6379); $list = M('Sms')->field('phone')-&g ...

  10. option_match

    //与match区别:如果没有匹配到,返回NULLCREATE (olive:Person {name:'Olive Stone'}),(charlie:Person {name:'Charlie S ...