codeforces contest 868 problem C(补集 状压)
2017-10-06 15:17
495 查看
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 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 and0 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
output
input
output
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行,每行k个数,选m行使每一位置 的相加个数和 不超过总个数的一半
解:k很小可以状压做 ,不超过一半的本质就是就是他的贡献不超过一半 那么直接让贡献小于等于1 枚举俩个补集就可以了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
typedef long long LL;
set<int>st;
int main()
{
st.clear();
int n, k;
scanf("%d %d", &n, &k);
for(int i=0; i<n; i++)
{
int x=0;
for(int j=0; j<k; j++)
{
int h;
scanf("%d", &h);
x|=(h<<j);
}
st.insert(x);
}
if(*(st.begin())==0)
{
puts("YES");
return 0;
}
for(auto i:st)
{
int now=(i^15);
for(int j=0; j<16; j++)
{
if((j&now)==j)
{
if(st.find(j)!=st.end())
{
puts("YES");
return 0;
}
}
}
}
puts("NO");
return 0;
}
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 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 and0 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行,每行k个数,选m行使每一位置 的相加个数和 不超过总个数的一半
解:k很小可以状压做 ,不超过一半的本质就是就是他的贡献不超过一半 那么直接让贡献小于等于1 枚举俩个补集就可以了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
typedef long long LL;
set<int>st;
int main()
{
st.clear();
int n, k;
scanf("%d %d", &n, &k);
for(int i=0; i<n; i++)
{
int x=0;
for(int j=0; j<k; j++)
{
int h;
scanf("%d", &h);
x|=(h<<j);
}
st.insert(x);
}
if(*(st.begin())==0)
{
puts("YES");
return 0;
}
for(auto i:st)
{
int now=(i^15);
for(int j=0; j<16; j++)
{
if((j&now)==j)
{
if(st.find(j)!=st.end())
{
puts("YES");
return 0;
}
}
}
}
puts("NO");
return 0;
}
相关文章推荐
- codeforces contest 868 problem D(玄学)
- Codeforces contest 311 problem E. Biologist(最大权闭合子图)
- codeforces com contest 855 problem D(数位DP)
- codeforces contest 343 problem D(线段树+dfs序)
- codeforces contest 785 problem E(分块)
- Codeforces Round #438 A+B+C Contest 868
- Codeforces Round #209 (Div. 2) Problem A Table(找规律)
- Codeforces Round #FF (Div. 2) Problem A DZY Loves Hash
- Codeforces April Fools Contest 2017
- Codeforces Round #430 (Div. 2) D.Vitya and Strange Lesson 异或 01字典树补集最小
- 742 B - Arpa’s obvious problem and Mehrdad’s terrible solution codeforces
- Codeforces Problem 711E ZS and The Birthday Paradox(抽屉原理+乘法逆元+费马小定理+组合数+快速幂+概率论)
- Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组
- Mike and gcd problem CodeForces - 798C
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
- Codeforces Problemset 30D(#30 div.1 D)
- Codeforces Round #400 (Div. 1 + Div. 2, combined)D - The Door Problem(2-sat)
- codeforces.com/contest/793
- Codeforces gym 2014 Nordic Collegiate Programming Contest(最初版,有过题再更新)
- Codeforces Round #169 (Div. 2):E - Little Girl and Problem on Trees