cf B. Berland Bingo

http://codeforces.com/contest/370/problem/B

题意:给你n个卡片,卡片上有m个不同的数字,这个游戏是随即的从袋子里面抽球,球上有数字1-100;如果第ith玩家比起他人卡片上的数字早读出来,就输出YES,有多个就输出NO。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <vector>
 4 #include <algorithm>
 5 #define maxn 100000
 6 using namespace std;
 7 
 8 int n;
 9 vector<int>g[maxn];
10 int ans[maxn];
11 
12 bool deal(int c1,int c2)
13 {
14     for(int i=0; i<(int)g[c1].size(); i++)
15     {
16         bool flag=false;
17         for(int j=0; j<(int)g[c2].size(); j++)
18         {
19             if(g[c1][i]==g[c2][j])
20             {
21                 flag=true;
22             }
23         }
24         if(!flag) return false;
25     }
26     return true;
27 }
28 
29 int main()
30 {
31     while(scanf("%d",&n)!=EOF)
32     {
33         for(int i=1; i<=n; i++)
34         {
35             g[i].clear();
36         }
37         for(int i=1; i<=n; i++)
38         {
39             int num;
40             scanf("%d",&num);
41             for(int j=1; j<=num; j++)
42             {
43                 int x;
44                 scanf("%d",&x);
45                 g[i].push_back(x);
46             }
47         }
48         for(int i=1; i<=n; i++)
49         {
50             ans[i]=1;
51         }
52         for(int i=1; i<=n; i++)
53         {
54             for(int j=i+1; j<=n; j++)
55             {
56                   if(deal(i,j)) ans[j]=0;
57                   if(deal(j,i)) ans[i]=0;
58             }
59         }
60         for(int i=1; i<=n; i++)
61         {
62             if(ans[i])
63             {
64                 printf("YES
");
65             }
66             else
67             printf("NO
");
68         }
69     }
70     return 0;
71 }
View Code
原文地址:https://www.cnblogs.com/fanminghui/p/3973170.html