CodeForces 370 B.Berland Bingo(模拟)

刺骨的言语ヽ痛彻心扉 2022-06-10 22:40 251阅读 0赞

Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains m**i numbers.

During the game the host takes numbered balls one by one from a bag. He reads the number aloud in a high and clear voice and then puts the ball away. All participants cross out the number if it occurs on their cards. The person who crosses out all numbers from his card first, wins. If multiple people cross out all numbers from their cards at the same time, there are no winners in the game. At the beginning of the game the bag contains 100 balls numbered 1 through 100, the numbers of all balls are distinct.

You are given the cards for each player. Write a program that determines whether a player can win the game at the most favorable for him scenario or not.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player’s card. The line that describes a card starts from integer m**i (1 ≤ m**i ≤ 100) that shows how many numbers the i-th player’s card has. Then follows a sequence of integers a**i, 1, a**i, 2, …, a**i, m**i(1 ≤ a**i, k ≤ 100) — the numbers on the i-th player’s card. The numbers in the lines are separated by single spaces.

It is guaranteed that all the numbers on each card are distinct.

Output

Print n lines, the i-th line must contain word “YES” (without the quotes), if the i-th player can win, and “NO” (without the quotes) otherwise.

Example

Input

  1. 3
  2. 1 1
  3. 3 2 4 1
  4. 2 10 11

Output

  1. YES
  2. NO
  3. YES

Input

  1. 2
  2. 1 1
  3. 1 1

Output

  1. NO
  2. NO

题解:

一道模拟题,遍历所有人模拟整个过程就好了,注意的是之前能胜出的人之后输了对该人输赢没影响这样一点就好了。。不过感觉模拟题都是要自己意会

代码:

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<map>
  4. #include<algorithm>
  5. #include<math.h>
  6. #include<queue>
  7. #include<stack>
  8. #include<string>
  9. #include<cstring>
  10. using namespace std;
  11. int vis[105];//-1为判断为输,1为判断为赢,0为还没判断
  12. int a[105][105];//记录第i个人持有哪些牌
  13. int p[105][105];//记录第i个人有的牌情况
  14. int num[105];//记录第i个人有几张牌
  15. int b[105];//复制牌数的数组
  16. int t[105];//用于储存赢的那些人的编号
  17. int main()
  18. {
  19. int i,j,k,s,n,x,tot,tag;
  20. scanf("%d",&n);
  21. for(i=0;i<n;i++)
  22. {
  23. memset(p[i],0,sizeof(p[i]));
  24. vis[i]=0;
  25. scanf("%d",&num[i]);
  26. for(j=0;j<num[i];j++)
  27. {
  28. scanf("%d",&a[i][j]);
  29. p[i][a[i][j]]=1;
  30. }
  31. sort(a[i],a[i]+num[i]);//排一下序时得去除牌时能够同时去除
  32. }
  33. for(i=0;i<n;i++)
  34. {
  35. if(vis[i]==1)//已经判断赢,不用判断
  36. continue;
  37. for(j=0;j<n;j++)
  38. b[j]=num[j];
  39. tag=0;
  40. tot=0;
  41. for(j=0;j<num[i];j++)//遍历这个人有的牌
  42. {
  43. for(k=0;k<n;k++)//遍历所有人
  44. {
  45. if(p[k][a[i][j]])//第k个人有这张牌
  46. {
  47. b[k]--;
  48. if(b[k]==0)//牌排除完了
  49. {
  50. tag=1;//局结束标记
  51. t[tot]=k;//记录胜者
  52. tot++;
  53. }
  54. }
  55. }
  56. if(tag)
  57. break;
  58. }
  59. vis[i]=-1;
  60. if(tot==1)
  61. {
  62. vis[t[0]]=1;//只有一个人赢的时候就是赢
  63. }
  64. else
  65. {
  66. for(j=0;j<tot;j++)
  67. {
  68. if(vis[t[j]]==1)//很重要,不计之后输的
  69. continue;
  70. vis[t[j]]=-1;//标记为输
  71. }
  72. }
  73. }
  74. for(i=0;i<n;i++)
  75. {
  76. if(vis[i]==-1)
  77. printf("NO\n");
  78. else
  79. printf("YES\n");
  80. }
  81. return 0;
  82. }

发表评论

表情:
评论列表 (有 0 条评论,251人围观)

还没有评论,来说两句吧...

相关阅读

    相关 bingo-培训——用户体验

    如何提高用户体验是软件开发中一个相当重要的问题,特别是互联网产品的用户体验关乎到用户的数量和产品的升值空间,那么用户体验究竟是什么,如何提高呢? ![这里写图片描述][So