codeforces 868C
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 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!
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.
这题比赛时1a了, 当时还挺开心,觉得自己暴力写了个O(N)的代码。结果结束后看人家的ac代码,顿时感觉自己是个zz。
我在想思路的时候,已经用四位数(题目指出最多四个队伍,我们可以假设一直都有四个队伍,也是不影响的)来表示了,但是还是没想到用二进制。
最后只能一点一点的用if来判断。
附我的ac代码:
1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <string>
5 #include <algorithm>
6 #include <cmath>
7 using namespace std;
8 const int maxn = 100005;
9 int nu[maxn][6];
10 int cnt[22];
11 int main() {
12 ios::sync_with_stdio(false);
13 int n,k;
14 cin>>n>>k;
15 for(int i = 0; i < n; i++) {
16 for(int j = 0; j < k; j++) {
17 cin>>nu[i][j];
18 }
19 }
20 for(int i = 0; i < n; i++) {
21 if(nu[i][0] == 0 ) {
22 if(nu[i][1] == 0) {
23 if(nu[i][2] == 0) {
24 if(nu[i][3] == 0) {
25 cnt[16]++;
26 }
27 else {
28 cnt[1]++;
29 }
30 }
31 else {
32 if(nu[i][3] == 0) {
33 cnt[2]++;
34 }
35 else{
36 cnt[10]++;
37 }
38 }
39 }
40 else {
41 if(nu[i][2] == 0) {
42 if(nu[i][3] == 0) {
43 cnt[3]++;
44 }
45 else {
46 cnt[9]++;
47 }
48 }
49 else {
50 if(nu[i][3] == 0) {
51 cnt[8]++;
52 }
53 else{
54 cnt[14]++;
55 }
56 }
57 }
58 }
59 else {
60 if(nu[i][1] == 0) {
61 if(nu[i][2] == 0) {
62 if(nu[i][3] == 0) {
63 cnt[4]++;
64 }
65 else {
66 cnt[7]++;
67 }
68 }
69 else {
70 if(nu[i][3] == 0) {
71 cnt[6]++;
72 }
73 else{
74 cnt[13]++;
75 }
76 }
77 }
78 else {
79 if(nu[i][2] == 0) {
80 if(nu[i][3] == 0) {
81 cnt[5]++;
82 }
83 else {
84 cnt[12]++;
85 }
86 }
87 else {
88 if(nu[i][3] == 0) {
89 cnt[11]++;
90 }
91 else{
92 cnt[15]++;
93 }
94 }
95 }
96 }
97 }
98 if(cnt[16]) cout<<"YES"<<endl;
99 else if(cnt[1]) {
100 if(cnt[2]||cnt[3]||cnt[4]||cnt[5]||cnt[6]||cnt[8]||cnt[11])
101 cout<<"YES"<<endl;
102 else cout<<"NO"<<endl;
103 }
104 else if(cnt[2]) {
105 if(cnt[3]||cnt[4]||cnt[5]||cnt[7]||cnt[9]||cnt[12])
106 cout<<"YES"<<endl;
107 else cout<<"NO"<<endl;
108 }
109 else if(cnt[3]) {
110 if(cnt[4]||cnt[6]||cnt[7]||cnt[10]||cnt[13])
111 cout<<"YES"<<endl;
112 else cout<<"NO"<<endl;
113 }
114 else if(cnt[4]) {
115 if(cnt[8]||cnt[9]||cnt[10]||cnt[14])
116 cout<<"YES"<<endl;
117 else cout<<"NO"<<endl;
118 }
119 else if(cnt[5]) {
120 if(cnt[10])
121 cout<<"YES"<<endl;
122 else cout<<"NO"<<endl;
123 }
124 else if(cnt[6]) {
125 if(cnt[9])
126 cout<<"YES"<<endl;
127 else cout<<"NO"<<endl;
128 }
129 else if(cnt[7]) {
130 if(cnt[8])
131 cout<<"YES"<<endl;
132 else cout<<"NO"<<endl;
133 }
134 else cout<<"NO"<<endl;
135
136 return 0;
137 }
附别人的ac代码:
1 #include<cstdio>
2 int n,k,a[17],b[5];
3 int main(){
4 scanf("%d%d",&n,&k);
5 while(n--){
6 for(int i=1;i<=k;i++)scanf("%d",&b[i]);
7 a[b[1]+b[2]*2+b[3]*4+b[4]*8]=1; //化为二进制
8 }
9 for(int i=0;i<=(1<<k);i++)
10 for(int j=i;j<=(1<<k);j++)
11 if(!(i&j)&&a[i]&&a[j]) //如果存在i和j四位都不同时为1 例:1010 0100
12 {puts("YES");return 0;}
13 puts("NO");
14 return 0;
15 }
codeforces 868C的更多相关文章
- F - Qualification Rounds CodeForces - 868C 二进制
F - Qualification Rounds CodeForces - 868C 这个题目不会,上网查了一下,发现一个结论就是如果是可以的,那么两个肯定可以满足. 然后就用二进制来压一下这个状态就 ...
- Codeforces 868C Qualification Rounds - 位运算
Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quar ...
- [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& ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- 浅入深出了解XXE漏洞
环境搭建 https://github.com/c0ny1/xxe-lab 为了更深入的理解,我准备理论和实际相结合的了解XXE! 浅谈XML 初识XML 一个好的代码基础能帮助你更好理解一类漏洞,所 ...
- 关于BAPI_TRANSACTION_COMMIT一点说明
我们调用bapi做了相关的业务操作后,通常都要在后面调用 BAPI_TRANSACTION_COMMIT来提交所做得更改 然而,有时候,在程序中需要调用多个不同的BAPI实现不同的功能,那么这个时候就 ...
- Hadoop2.7.7阿里云安装部署
阿里云的网络环境不需要我们配置,如果是在自己电脑上的虚拟机,虚拟机的安装步骤可以百度.这里是单机版的安装(也有集群模式的介绍)使用Xshell连接阿里云主机,用命令将自己下载好的安装包上传到服务器 # ...
- LSM(Log Structured Merge Trees ) 笔记
目录 一.大幅度制约存储介质吞吐量的原因 二.传统数据库的实现机制 三.LSM Tree的历史由来 四.提高写吞吐量的思路 4.1 一种方式是数据来后,直接顺序落盘 4.2 另一种方式,是保证落盘的数 ...
- 阿里云VPC网络内网实例通过SNAT连接外网
场景: 1.有多个ECS实例,其中A实例有公网IP,可以上外网 其它实例没有公网IP,不能上外网 2.所有实例在一个交换机,也就是一个网络(172.16.0.0/16) 实例 内网IP 外网IP A ...
- 网络编程 — Linux TCP服务端和客户端
1. 服务端 #include <stdlib.h> #include <string.h> #include <errno.h> #include <sig ...
- centos7防火墙firewalld拒绝某ip或者某ip段访问服务器任何服务
安装firewall后(LINUX7系统一般情况下默认已安装),防火墙默认配置是只打开SSH端口的,也就是22端口,如果SSH的端口已更改成别的端口了,请切记一定在启动firewall前先修改对应服务 ...
- Python+Selenium+Unittest实现PO模式web自动化框架(3)
1.Outputs目录下的具体目录功能 2.logs目录 logs目录是用于存放log日志的一个目录. 2.reports目录 reports目录是用于存放测试报告的. 3.screenshots目录 ...
- 记一次压测问题定位:connection reset by peer,TCP三次握手后服务端发送RST_网络_c359719435的专栏-CSDN博客 https://blog.csdn.net/c359719435/article/details/80300433
记一次压测问题定位:connection reset by peer,TCP三次握手后服务端发送RST_网络_c359719435的专栏-CSDN博客 https://blog.csdn.net/c3 ...
- Page (computer memory) Memory segmentation Page table 虚拟地址到物理地址的转换
A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described ...