Codeforces 868C Qualification Rounds【思维】
来源:互联网 发布:上海 现代建筑 知乎 编辑:程序博客网 时间:2024/05/21 05:06
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 31 0 11 1 01 0 01 0 01 0 0
NO
3 21 01 10 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.
题目大意:
让我们找出一个非空子集,使得子集中每个位子上的1的数字加和数量小于等于子集大小的一半。‘
思路:
①我们选择的题目数量多少其实对结果的影响并不大,我们问题其实只要选1个题或者两个题就能够完成目标的话,没必要选更多的题目来给大家做
②所以问题就是在找一道题或者两道题来满足题意要求
③找一道题很简单,必须都是0
④如果选两道题的话,那么使得这两道题每一位子上的数加和小于等于1就行了
那么我们O(n)枚举一道题,然后O(16)枚举另外一道题,然后寻找是否存在即可
总时间复杂度O(16*n)
当然我们也可以再优化一手,时间复杂度达到O(16*16)【四位二进制枚举】
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;int vis[2][2][2][2];int b[150000][5];int Slove(int a,int b,int c,int d){ for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { for(int k=0;k<2;k++) { for(int l=0;l<2;l++) { if(vis[i][j][k][l]>0) { if(a+i<=1&&b+j<=1&&c+k<=1&&d+l<=1)return 1; } } } } } return 0;}int main(){ int n,k; while(~scanf("%d%d",&n,&k)) { int flag=0; memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) { int a[5]; int temp=0; memset(a,0,sizeof(a)); for(int j=0;j<k;j++) { scanf("%d",&a[j]); if(a[j]!=0)temp=1; } if(temp==0)flag=1; vis[a[0]][a[1]][a[2]][a[3]]++; b[i][0]=a[0]; b[i][1]=a[1]; b[i][2]=a[2]; b[i][3]=a[3]; } for(int i=1;i<=n;i++) { if(Slove(b[i][0],b[i][1],b[i][2],b[i][3])==1)flag=1; } if(flag==1)printf("YES\n"); else printf("NO\n"); }}
- Codeforces 868C Qualification Rounds【思维】
- Codeforces 868 C Qualification Rounds
- codeforces 868C Qualification Rounds
- codeforces 868C Qualification Rounds
- Codeforces 868C Qualification Rounds
- Codeforces 868C Qualification Rounds
- CodeForces 868C Qualification Rounds
- codeforces 868C Qualification Rounds
- Codeforces 868 C. Qualification Rounds (技巧)
- Codeforces 868C Qualification Rounds 结论
- Codeforces Round #438 C 868C Qualification Rounds(思维,非状压dp)
- 【状态压缩 && 思维转换】Codeforces Round #438 868C Qualification Rounds
- Codeforces round438 C. Qualification Rounds
- codeforces 868C.Qualification Rounds(bitmasks与状压dp)
- Codeforces Round #438 C. Qualification Rounds
- Codeforces Round #438 C. Qualification Rounds 二进制
- codeforces round #438 C. Qualification Rounds
- Codeforces Round #438 C. Qualification Rounds 题解
- 用JavaScript代码编写日历
- 财商低的六大表现!你中招了吗?
- JavaScript执行上下文,执行上下文栈
- 设计模式——装饰者模式
- 视频基础知识
- Codeforces 868C Qualification Rounds【思维】
- 线程初步(二)
- MyBatis Generator系列(三)----修改源码实现中文注释
- 用正则写了小区判断,回忆了一点正则知识
- 【精华】PS快捷键及小技巧集锦
- jQuery实现全选功能
- MacOS 开发
- source insight窗口恢复默认
- 【51 nod 1090 三个数和为0】