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的更多相关文章
随机推荐
- Liunx Pwd
Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...
- (转)wcf项目程序调试
由于使用分布式开发,因此在调试时,要分为客户端调试和服务端调试两种情况,下面就对这两种情况的调试步骤分别加以详细说明 调试客户端的页面代码 当仅仅需要调试客户端代码时,按照以下步骤进行操作: 1. ...
- 解决 win 7 64 位 vs2010 调试silverlight项目无法加载,提示更新developer ,跟新报 消息 ID: 1517 已安装了 Silverlight 的 64 位版本
出现上面的问题是我们安装的silverlight的版本和系统给的silverlight下载的版本冲突, 解决的方法是,首先卸载Silverlight runtime(也就是默认的silverlight ...
- JTable 查询
public JTable query(String table) throws SQLException { DefaultTableModel tablemodel = new DefaultTa ...
- fedora 使用
我们在这篇指南中将介绍安装Fedora 23工作站版本后要完成的一些实用操作,以便用起来更爽. 1.更新Fedora 23程序包 哪怕你可能刚刚安装/升级了Fedora 23,仍很可能会有需要更新的程 ...
- java 环境搭建
一.安装jdk 下载jdk http://www.oracle.com/technetwork/java/javase/downloads 将下载的jdk文件放到 /opt 下解压 $sudo cp ...
- Two Sum II - Input array is sorted LT167
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- java调用第三方包的例子
第三方包路径 D:\jp\log4j\log4j-1.2.16.jar 代码D:\jp\log4j\Log4jDemo.java import org.apache.log4j.*; public c ...
- SpringMVC学习笔记:单例与并发问题
Spring中的Bean默认都是单例(singleton),Spring中Bean的scope属性有五种类型: singleton 表示在spring容器中的单例,通过spring容器获得该bean时 ...
- 2017/2/16:自己ajax+json习惯性写法 代码拼接的写法 +json用post提交乱码的原因
1.先导入jquery的包 2.ajax的写法跟注意点 返回一个list的写法 代码拼接写法: html层: 2.script处 4:在你前面传递参数的时候没有遇到乱码问题的情况下,你使用json并且 ...