zoukankan      html  css  js  c++  java
  • B. Berland Bingo

    Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers.

    During the game the host takes numbered balls one by one from a bag. He reads the number aloud in a high and clear voice and then puts the ball away. All participants cross out the number if it occurs on their cards. The person who crosses out all numbers from his card first, wins. If multiple people cross out all numbers from their cards at the same time, there are no winners in the game. At the beginning of the game the bag contains 100 balls numbered 1 through 100, the numbers of all balls are distinct.

    You are given the cards for each player. Write a program that determines whether a player can win the game at the most favorable for him scenario or not.

    Input

    The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, 2, ..., ai, mi (1 ≤ ai, k ≤ 100) — the numbers on the i-th player's card. The numbers in the lines are separated by single spaces.

    It is guaranteed that all the numbers on each card are distinct.

    Output

    Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.

    Sample test(s)
    input
    3
    1 1
    3 2 4 1
    2 10 11
    output
    YES
    NO
    YES
    input
    2
    1 1
    1 1
    output
    NO
    NO

    AC代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 typedef struct
     5 {
     6     int t;
     7     int a[105];
     8     char str[5];
     9 }Play;
    10 Play player[105];
    11 int cmp(const void *a,const void *b)
    12 {
    13     return *(int *)a-*(int *)b;
    14 }
    15 
    16 int find(int m,int i)
    17 {
    18     int l,r,mid;
    19     l = 0;
    20     r = player[i].t-1;
    21     while(l <= r)
    22     {
    23         mid = (l + r) >> 1;
    24         if(m == player[i].a[mid])
    25             return 0;
    26         if(m < player[i].a[mid])
    27             r = mid - 1;
    28         else
    29             l = mid + 1;
    30     }
    31     return 1;
    32 }
    33 
    34 int main()
    35 {
    36     int n,i,j,k;
    37     int flag,t;
    38     while(~scanf("%d",&n))
    39     {
    40         for(i = 0;i < n;i ++)
    41             strcpy(player[i].str,"YES");
    42         for(i = 0;i < n;i ++)
    43         {
    44             scanf("%d",&t);
    45             player[i].t = t;
    46             for(j = 0; j < t; j ++)
    47             {
    48                 scanf("%d",&player[i].a[j]);
    49             }
    50             qsort(player[i].a,t,sizeof(player[i].a[0]),cmp);
    51         }
    52         for(i = 0;i < n;i ++)
    53         {
    54             if(!strcmp(player[i].str,"YES"))
    55             {
    56                 for(j = i + 1;j < n;j ++)
    57                 {
    58                     flag = 0;
    59                     if(!(player[i].t < player[j].t))
    60                     {
    61                         for(k = 0; k < player[j].t;k ++)
    62                         {
    63                             if(find(player[j].a[k],i))
    64                                 flag = 1;
    65                         }
    66                         if(!flag)
    67                         {
    68                             strcpy(player[i].str,"NO");
    69                             if(player[i].t == player[j].t)
    70                                 strcpy(player[j].str,"NO");
    71                         }
    72                     }
    73                     else
    74                     {
    75                         for(k = 0;k < player[i].t;k ++)
    76                         {
    77                             if(find(player[i].a[k],j))
    78                                 flag = 1;
    79                         }
    80                         if(!flag)
    81                             strcpy(player[j].str,"NO");
    82                     }
    83                 }
    84             }
    85         }
    86         for(i = 0;i < n;i ++)
    87             printf("%s
    ",player[i].str);
    88     }
    89     return 0;
    90 }
    
    
  • 相关阅读:
    JS高阶---继承模式(原型链继承)
    一切皆数据,人生需学习
    操作系统升级
    看了跨年演讲后
    新的开始
    怎么做一名高薪前端工程师,必备哪些技术工具?
    web服务器 Nginx
    实用的软件架构方法
    购买网络自动化工具时应考虑的7个方面
    ES6 展开操作符的几个妙用
  • 原文地址:https://www.cnblogs.com/anhuizhiye/p/3463358.html
Copyright © 2011-2022 走看看