Cinema(CF-234D)

Problem Description

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.

Examples

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.

题意:有 m 个编号从 1 到 m 的演员,现在有 k 个喜欢的演员,并给出喜欢的演员编号,然后给出 n 部电影的名称、演员数以及演员序号,其中 0 代表不确定的演员序号,现在要判断每一电影的喜爱程度,最喜欢的电影输出 0,一定不是最喜欢的电影输出 1,不确定的电影输出 2,对于最喜欢的电影,其定义为某部电影中他喜欢的演员人数大于等于其他电影中他喜欢的演员数

思路:由于数据范围不大,因此直接暴力即可,对于每一部电影,由于 0 的存在,因此可以判断里面喜欢的演员的最大值与最小值,然后对于 n 个电影最小值与最大值,进行比较:

  • 如果某电影确定喜欢的人数 >= 其他电影最多喜欢的演员人数,  则这个肯定为最喜欢的电影,即为 0
  • 如果某电影最多喜欢的演员人数,存在其他电影确定喜欢的人数比这部电影大,  则这个肯定不是最喜欢的电影,即为 1
  • 其他的情况是不确定的,即为 2

此外,注意本题要使用文件读写

Source Program

#include<bits/stdc++.h>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

struct Node{
    char name[N];
    int d;
    int b[N];
}node[N];
int a[N];
bool bucket[N];
int maxx[N],minn[N];

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int m,k;
    scanf("%d%d",&m,&k);
    for(int i=1;i<=k;i++){
        scanf("%d",&a[i]);
        bucket[a[i]]=true;
    }

    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",node[i].name);
        scanf("%d",&node[i].d);
        for(int j=1;j<=node[i].d;j++){
            scanf("%d",&node[i].b[j]);
        }
    }

    for(int i=1;i<=n;i++){
        int love=k;
        int maybe=0;
        int other=m-k;
        int newLove=0;
        for(int j=1;j<=node[i].d;j++){
            int b=node[i].b[j];
            if(b==0)
                maybe++;
            else if(!bucket[b])
                other--;
            else if(bucket[b]){
                love--;
                newLove++;
            }
        }
        if(love>=maybe)
            maxx[i]=newLove+maybe;
        else
            maxx[i]=newLove+love;
        if(other>=maybe)
            minn[i]=newLove;
        else
            minn[i]=newLove+maybe-other;
    }

    for(int i=1;i<=n;i++){
        int cnt=1;
        while(cnt<=n){
            if(cnt!=i&&maxx[cnt]>minn[i])
                break;
            cnt++;
        }
        if(cnt>n)
            printf("0\n");
        else{
            int tot=1;
            while(tot<=n){
                if(tot!=i&&maxx[i]<minn[tot])
                    break;
                tot++;
            }
            if(tot<=n)
                printf("1\n");
            else
                printf("2\n");
        }
    }

    return 0;
}

 

posted @ 2022-09-20 22:52  老程序员111  阅读(91)  评论(0)    收藏  举报