zoukankan      html  css  js  c++  java
  • codeforces 868C

    C. 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 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!

    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 and 0 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.

    这题比赛时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 }
    View Code

    附别人的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 }
    View Code
  • 相关阅读:
    【1】maven来管理我的SSM项目
    mybatis从数据库中取到的date格式不是yyyy-MM-dd HH:mm:ss
    hadoop的webUI查看Live Nodes为1
    CentOS6.8系统下,ecipse下进行编辑操作,意外退出
    【5】namenode启动过程
    电脑意外重启,导致虚拟机启动失败
    第3章 路由和数据传递
    第2章 基于三层架构搭建MVC系统
    第1章 进入ASP.NET MVC世界
    第13章 集合
  • 原文地址:https://www.cnblogs.com/zmin/p/7630296.html
Copyright © 2011-2022 走看看