CodeForces 370 B.Berland Bingo(模拟)

97 篇文章 0 订阅

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.

Example
Input
3
1 1
3 2 4 1
2 10 11
Output
YES
NO
YES
Input
2
1 1
1 1
Output
NO
NO

题解:

一道模拟题,遍历所有人模拟整个过程就好了,注意的是之前能胜出的人之后输了对该人输赢没影响这样一点就好了。。不过感觉模拟题都是要自己意会

代码:

#include<iostream>
#include<stdio.h>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
using namespace std;
int vis[105];//-1为判断为输,1为判断为赢,0为还没判断
int a[105][105];//记录第i个人持有哪些牌
int p[105][105];//记录第i个人有的牌情况
int num[105];//记录第i个人有几张牌
int b[105];//复制牌数的数组
int t[105];//用于储存赢的那些人的编号
int main()
{
    int i,j,k,s,n,x,tot,tag;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        memset(p[i],0,sizeof(p[i]));
        vis[i]=0;
        scanf("%d",&num[i]);
        for(j=0;j<num[i];j++)
        {
            scanf("%d",&a[i][j]);
            p[i][a[i][j]]=1;
        }
        sort(a[i],a[i]+num[i]);//排一下序时得去除牌时能够同时去除
    }
    for(i=0;i<n;i++)
    {
        if(vis[i]==1)//已经判断赢,不用判断
            continue;
        for(j=0;j<n;j++)
            b[j]=num[j];
        tag=0;
        tot=0;
        for(j=0;j<num[i];j++)//遍历这个人有的牌
        {
            for(k=0;k<n;k++)//遍历所有人
            {
                if(p[k][a[i][j]])//第k个人有这张牌
                {
                    b[k]--;
                    if(b[k]==0)//牌排除完了
                    {
                        tag=1;//局结束标记
                        t[tot]=k;//记录胜者
                        tot++;
                    }
                }
            }
            if(tag)
                break;
        }
        vis[i]=-1;
        if(tot==1)
        {
            vis[t[0]]=1;//只有一个人赢的时候就是赢
        }
        else
        {
            for(j=0;j<tot;j++)
            {
                if(vis[t[j]]==1)//很重要,不计之后输的
                   continue;
                vis[t[j]]=-1;//标记为输
            }
        }
    }
    for(i=0;i<n;i++)
    {
        if(vis[i]==-1)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值