CodeForces 240A A. Cinema 解题报告

A. Cinema
time limit per test
1 second
memory limit per test
256 megabytes
input
input.txt
output
output.txt

Overall there are m actors in Berland. Each actor has a personal identifier — an integer from 1 to m (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has k favorite actors. He watched the movie trailers for the next month and wrote the following information for every movie: the movie title, the number of actors who starred in it, and the identifiers of these actors. Besides, he managed to copy the movie titles and how many actors starred there, but he didn't manage to write down the identifiers of some actors. Vasya looks at his records and wonders which movies may be his favourite, and which ones may not be. Once Vasya learns the exact cast of all movies, his favorite movies will be determined as follows: a movie becomes favorite movie, if no other movie from Vasya's list has more favorite actors.

Help the boy to determine the following for each movie:

    • whether it surely will be his favourite movie;

    • whether it surely won't be his favourite movie;

    • can either be favourite or not.

    Input

    The first line of the input contains two integers m and k (1 ≤ m ≤ 100, 1 ≤ k ≤ m) — the number of actors in Berland and the number of Vasya's favourite actors.

    The second line contains k distinct integers ai (1 ≤ ai ≤ m) — the identifiers of Vasya's favourite actors.

    The third line contains a single integer n (1 ≤ n ≤ 100) — the number of movies in Vasya's list.

    Then follow n blocks of lines, each block contains a movie's description. The i-th movie's description contains three lines:

    • the first line contains string si (si consists of lowercase English letters and can have the length of from 1 to 10 characters, inclusive) — the movie's title,

    • the second line contains a non-negative integer di (1 ≤ di ≤ m) — the number of actors who starred in this movie,

    • the third line has di integers bi, j (0 ≤ bi, j ≤ m) — the identifiers of the actors who star in this movie. If bi, j = 0, than Vasya doesn't remember the identifier of the j-th actor. It is guaranteed that the list of actors for a movie doesn't contain the same actors.

      All movies have distinct names. The numbers on the lines are separated by single spaces.

    Output

    Print n lines in the output. In the i-th line print:

    • 0, if the i-th movie will surely be the favourite;
    • 1, if the i-th movie won't surely be the favourite;
    • 2, if the i-th movie can either be favourite, or not favourite.

    Sample test(s)
    input
    5 3
    1 2 3
    6
    firstfilm
    3
    0 0 0
    secondfilm
    4
    0 0 4 5
    thirdfilm
    1
    2
    fourthfilm
    1
    5
    fifthfilm
    1
    4
    sixthfilm
    2
    1 0
    
    output
    2
    2
    1
    1
    1
    2
    
    input
    5 3
    1 3 5
    4
    jumanji
    3
    0 0 0
    theeagle
    5
    1 2 3 4 0
    matrix
    3
    2 4 0
    sourcecode
    2
    2 4
    
    output
    2
    0
    1
    1
    
    Note

    Note to the second sample:

    • Movie jumanji can theoretically have from 1 to 3 Vasya's favourite actors.
    • Movie theeagle has all three favourite actors, as the actor Vasya failed to remember, can only have identifier 5.
    • Movie matrix can have exactly one favourite actor.
    • Movie sourcecode doesn't have any favourite actors.

    Thus, movie theeagle will surely be favourite, movies matrix and sourcecode won't surely be favourite, and movie jumanji can be either favourite (if it has all three favourite actors), or not favourite.




    题目很长,简单介绍下题意吧,就是给多不电影,判断每一电影一定是某人最喜爱的0,一定不是某人最喜爱的1,不确定的话输出2;

    如果是某人喜爱的电影的话,那么该部电影中他最喜欢的演员的人数大于等于其他影片中他喜爱的演员数目;

    每部电影所获的信息,电影名(无用);演员人数,还有演员的名单(用1-n的编号标定,如果不确定的话就是0);

    因为数据规模很小,所以就用最暴力的做法,对于每一部电影,判断里面某人喜爱演员的最小值和最大值,然后如果最小值比其他所有的电影的最大值,如果不小于的话就是0; 然后在判断不确定的情况,最后才是一定不是的情况……按这个顺序判断,用最暴力的做法就能A


    #include<cstring>
    #include<iostream>
    #include<cstdio>
    
    using namespace std;
    
    struct Node
    {
        int mmin,mmax;
    }nod[110];
    string str;
    int fav[110];
    bool vis[110];
    int m,k,n;
    int c1,c2;
    
    int check(int x)
    {///先判断一定是,咱判断可能是,最后肯定是:一定不是
        int ret=0;
        bool bo=true;
        for(int i=0;i<n;++i)
        {
            if(i!=x)
            {
                if(bo&&nod[x].mmin>=nod[i].mmax)continue;
                else{ bo=false;break;}
            }
        }
        if(bo)return 0;
        bo=1;
        for(int i=0;i<n;++i)
        {
            if(i!=x)
            {
                if(bo&&nod[x].mmax>=nod[i].mmin)continue;
                else{ bo=false;break; }
            }
        }if(bo)return 2;
    
    
        return 1;
    
    }
    int main()
    {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    
        while(cin>>m>>k)
        {
            memset(vis,0,sizeof(vis));
            for(int i=0;i<k;++i)
            {
                cin>>fav[i]; vis[fav[i]]=1;
            }
            cin>>n;
            int t;
            c1=k;  c2=m-k;
    
    
            for(int i=0;i<n;++i)
            {   int t1=c1,t2=c2,t3=0;
                cin>>str;
                cin>>t; int tmp;
                for(int j=0;j<t;++j)
                {
                    cin>>tmp;
                    if(tmp==0)t3++;///不确定的演员
                    else if(vis[tmp])t1--;///剩下的fav演员
                    else t2--;///剩下的一般演员
                }
                int t4=c1-t1,t5=t2;
                if(t3)
                {
                    t4+=min(t1,t3);///喜爱的演员数目还能增加吗
                    nod[i].mmin=c1-t1;
                    nod[i].mmax=t4;
                    if(t5<t3)nod[i].mmin+=t3-t5;///由于不喜爱的演员数目不能全部填满,所以最小值……
                }else nod[i].mmax=nod[i].mmin=t4;
    
            }
    
            for(int i=0;i<n;++i)
            {
               // cout<<nod[i].mmin<<" == "<<nod[i].mmax<<endl;
                cout<<check(i)<<endl;
            }
    
        }
        return 0;
    }
    


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

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值