cf B. Berland Bingo

本文解析了一个Codeforces竞赛题目,该题目涉及多个玩家比较手中卡片数字的先后顺序。通过C++代码实现了一种算法来判断玩家间卡片数字的关系,并据此确定每位玩家是否能够比其他人更快地读出数字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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\n");
65             }
66             else
67             printf("NO\n");
68         }
69     }
70     return 0;
71 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/3973170.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值