Codeforces Round #145 (Div. 2) D. Cinema

题目链接:

http://codeforces.com/problemset/problem/234/D

D. Cinema

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.

Examples

input

Copy

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

Copy

2
2
1
1
1
2

input

Copy

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

Copy

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名电影演员,k个喜欢的电影演员,t场电影,每场电影有q个演员,这q个演员,1-m之间数字表示确定已知的演员,0表示未知的演员,对与每一场电影做出回答:0确定最喜欢,1确定不是最喜欢,2不确定

0确定最喜欢的电影:在未知演员优先为喜欢演员的情况下,当前电影的确定喜欢演员的人数大于等于其它电影最多可能喜欢的演员的人数时是最喜欢的

1 确定不喜欢的电影:存在任意一部电影中确定喜欢的演员的人数都比这部电影最多可能喜欢的电影的人数要多,所以不是最喜欢的

2 不确定最喜欢的:其他情况

This is the code:

#include<bits/stdc++.h>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int dr[]={0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]={-1, 1, 0, 0, -1, 1, -1, 1};
inline int read()//输入外挂
{
    int ret=0, flag=0;
    char ch;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        ret = ch - '0';
    while((ch=getchar())>='0'&&ch<='9')
        ret=ret*10+(ch-'0');
    return flag ? -ret : ret;
}
struct node
{
    int zero;//0的个数
    int no;//不喜欢的人数
    int like;//已知喜欢的人数

    int max_like;//最多可能喜欢
    int min_like;//最少可能喜欢,即一定喜欢的

}a[105];
int x[105];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int m,k;
    int tem;
    scanf("%d%d",&m,&k);
    for(int i=1;i<=k;++i)
    {
        scanf("%d",&tem);
        x[tem]=1;
    }
    int t;
    scanf("%d", &t);
    string s;
    int q;
    int maxxx=0;
    int minnn=0;
    for(int i=1;i<=t;++i)
    {
        cin>>s;
        scanf("%d",&q);
        for(int j=1;j<=q;++j)
        {
            scanf("%d",&tem);
            if(tem==0)
                a[i].zero++;
            else if(x[tem])
                a[i].like++;
            else
                a[i].no++;
        }
        a[i].max_like=a[i].like+min(a[i].zero,k-a[i].like);     //最多喜欢的
        a[i].min_like=a[i].like+max(0,a[i].zero-(m-k-a[i].no)); //最少喜欢的,即一定喜欢的
        maxxx=max(maxxx,a[i].max_like);
        minnn=max(minnn,a[i].min_like);

    }
    //0 最喜欢的,只有一个 ,如果max_num>=2,表示不存在有最喜欢的电影
    //1 不喜欢的,
    //2 不0确定是不是最喜欢的
    for(int i=1;i<=t;++i)
    {
        bool flag=false;
        for(int j=1;j<=t;++j)
        {
            if(i!=j && a[i].max_like<a[j].min_like)
            {
                //最好的都比最差的小,所以一定是不喜欢的
                printf("1\n");
                flag=true;
                break;
            }
        }
        if(flag)
            continue;

        for(int j=1;j<=t;++j)
        {
            if(i!=j && a[i].min_like<a[j].max_like)
            {
                //最差的没有比最好的都好,所以不确定是否最好
                printf("2\n");
                flag=true;
                break;
            }
        }
        if(flag)
            continue;
        printf("0\n");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值