Codeforces 868C Qualification Rounds - 位运算
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 0otherwise.
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.
题目大意 有k个队参加比赛,有n道题目待选,是否可以选出一些题目使得每个队最多能做出选出的总题数
在比赛的时候,根据人生的哲理和数学的直觉可以发现,其实能选出2个题目满足条件就行了。
于是你把每个题目当成k位的二进制数,原题等价于选出两个数,使得它们and后的结果为0.
这个可以把其中一个转化成补集,然后再枚举子集打flag,边读边打标记边判断,然后就完了。
至于正确性的证明,只有1的队的时候显然,我就证一下只有2个队的情况
已知选出了x(x > 3)个题目使得满足条件。求证其中存在两个题目就能满足条件
1)当某一个是0 0,显然成立
2)当某一个存在一个1,因为有不少于一半的那一位都是0,所以成立
3)当某一个两位都是1,那么至多总共有x个1,除去这个至多有(x - 2)个1,但还剩下(x - 1)道题,根据鸽巢原理,一定存在一个是0 0.
当存在3个队时,很多情况同理(不等式仍然满足,可以独立几列进行分析),当存在某一个3位都是1的时候,先考虑前两位,根据上面的情况3可以得到一定存在0 0 1或0 0 0,再考虑后两位,可以得到一定存在1 0 0或0 0 0,然后选出这个两个,完事。
对于4个队的时候同理。
(以上证明是自己证的,有问题请一定要指出)
Code
/**
* Codeforces
* Problem#868C
* Accepted
* Time: 78ms
* Memory: 0k
*/
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean; int n, k; inline void init() {
scanf("%d%d", &n, &k);
} boolean vis[];
inline void solve() {
int rev_flag = ( << k) - ;
for(int i = , num, x; i <= n; i++) {
num = ;
for(int j = ; j < k; j++)
scanf("%d", &x), num <<= , num += x;
if(!num || vis[num]) {
puts("YES");
return;
}
num ^= rev_flag;
for(int s = num; s; s = (s - ) & num)
vis[s] = true;
}
puts("NO");
} int main() {
init();
solve();
return ;
}
Codeforces 868C Qualification Rounds - 位运算的更多相关文章
- [Codeforces Round #438][Codeforces 868C. Qualification Rounds]
题目链接:868C - Qualification Rounds 题目大意:有\(n\)个题目,\(k\)个人,每个人可能做过这\(n\)个题里的若干道,出题方要在这\(n\)个题目里选若干个出来作为 ...
- codeforces 868C - Qualification Rounds(构造)
原题链接:http://codeforces.com/problemset/problem/868/C 题意:有k个队伍参加比赛,比赛有n个预选的题目,有些队伍对已经事先知道了一些题目.问能不能选出若 ...
- codeforces 868C Qualification Rounds
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quar ...
- 【Codeforces】868C. Qualification Rounds
[题目]C. Qualification Rounds [题意]给定n个问题和K个人,给定每个人知道的问题列表,求能否找到一个非空问题集合,满足每个人知道的集合中问题数量都不超过集合总题数的一半.n& ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- codeforces - 15C Industrial Nim(位运算+尼姆博弈)
C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...
- Codeforces 878A - Short Program(位运算)
原题链接:http://codeforces.com/problemset/problem/878/A 题意:给出n个位运算操作, 化简这些操作, 使化简后的操作次数不多于5步. 思路:我们可以对二进 ...
- CodeForces - 1230D(思维+位运算)
题意 https://vjudge.net/problem/CodeForces-1230D 要组建一个小组,要求小组中每个人都不比所有人强,当一个人懂得一个算法但是另一个不懂那么前者认为他比后者强. ...
- F - Qualification Rounds CodeForces - 868C 二进制
F - Qualification Rounds CodeForces - 868C 这个题目不会,上网查了一下,发现一个结论就是如果是可以的,那么两个肯定可以满足. 然后就用二进制来压一下这个状态就 ...
随机推荐
- 关于如何利用计算属性进行button的控制
element分页没用它的 (这个只要上一页下一页),比如共2页的时候,你在第一页,你肯定可以点击下一页,当你进入到第二页的时候这个button肯定就不能点击了啊,它的属性diaabled=true让 ...
- UGUI之Scrollbar使用
这个效果主要用到了3个组件(对象): 1:Scrollbar对象 滚动条 2:Scroll Rect组件 让对象具有滑动效果 3:Mask组件 遮罩层.把多余的部分隐藏不显示 Scrollbar ...
- .net中ashx文件有什么用?功能有那些,一般用在什么情况下?
.ashx是“一般处理文件”.和aspx类似.但是这种文件要比aspx这种前台页面文件内容简单轻巧..ashx不提供前台展示的功能.也可以说它结合了.cs类文件而且又可以提供给.aspx文件做UI层的 ...
- spring自带的定时任务功能@EnableScheduling
1 demo package com.test.domi.config; import org.springframework.beans.factory.annotation.Configurabl ...
- 《大话设计模式》c++实现 建造者模式
一.UML图 关键词:Subject维护一个Observer列表,Subject执行Notify()时就执行列表中的每个Observer的Update(). 二.概念 观察者模式:定义了一种一对多的依 ...
- linux常见运维题
linux运维题 一.填空题 1. 在Linux 系统 中,以文件方式访问设备 . (linux下一切都是文件) 2. Linux 内核引导时,从文件/etc/fstab中读取要加载的文件系统 . ( ...
- sublime text3 增加代码片段(snipper)
有时候编写代码时有些代码片段经常会用到,如果能将这些代码片段整理,再在需要的时候通过某些条件触发,那无疑是非常方便的! 创建方法:工具->插件开发->新建代码片段 默认产生的内容是: &l ...
- .net 学习笔记2
托管代码.非托管代码 语法糖: 写C#代码时,遵守简单的语法.编译时编译器将简单的写法编译成正式的复杂的写法. 如: 上面简写了方法,编译时编译器帮助生成完整的代码 Var 关键字指示 编译器 ...
- 【Hive学习之八】Hive 调优【重要】
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...
- neuFlow&CNP-卷积计算加速器&神经网络加速芯片生态系统
上周看到韩松毕业论文,扯出神经网络加速器EIE,刚好这周调研了一下neuFlow,扯出09年的一篇做卷积加速的文章,大牛Lecun Yan的学生做的,一晃眼,快十年了.也记录之. 这一套还没研究透,又 ...