CF 370B Berland Bingo

时间:2023-03-09 18:34:24
CF 370B Berland Bingo

题目链接: 传送门

Berland Bingo

time limit per test:1 second     memory limit per test:256 megabytes

Description

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 Input

3
1 1
3 2 4 1
2 10 11

2
1 1
1 1

Sample Output

YES
NO
YES

NO
NO

解题思路:

题目大意:每个人手上都有几个数字,裁判扔数字,当自己手上有跟裁判扔出的数字一样的数,就把这张牌丢弃,问谁能胜利
其实这题就是问那个人没有子集,没有子集的最后都能胜利。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

bool OK(vector<int>a,vector<int>b)//a in b?
{
    int lena = a.size();
    int lenb = b.size();
    for (int i = 0;i < lena;i++)
    {
        bool in = false;
        for (int j = 0;j < lenb;j++)
        {
            if (a[i] == b[j])
            {
                in = true;
            }
        }
        if (!in)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int N;
    while (~scanf("%d",&N))
    {
        vector<int>itv[105];
        int ans[105] = {0};
        int M,tmp;
        for (int i = 0;i < N;i++)
        {
            scanf("%d",&M);
            while (M--)
            {
                scanf("%d",&tmp);
                itv[i].push_back(tmp);
            }
        }
        for (int i = 0;i < N;i++)
        {
            for (int j = 0;j < N;j++)
            {
                if (j == i) continue;
                if (OK(itv[i],itv[j]))
                {
                    ans[j] = 1;
                }
            }
        }
        for (int i = 0;i < N;i++)
        {
            if (!ans[i])
            {
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }
        }
    }
    return 0;
}