codeforces 370B Berland Bingo(强势模拟)
来源:互联网 发布:网页美工教程 编辑:程序博客网 时间:2024/06/05 00:18
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 mi 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.
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 mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, 2, ..., ai, mi(1 ≤ ai, 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.
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.
31 13 2 4 12 10 11
YESNOYES
21 11 1
NONO
【题解】这道题是条件限制比较多的模拟题,题意是有n个人,还有一个荷官(其实就是一个喊号的~~),n个人每个人都有一张牌,牌上有一些数字(每个人的牌上没有相同的数字),现在荷官手里有一个袋子,里面是100个标号1~100的号码,每次从袋子里拿出一个号码念一下,所有n个人中凡是手中牌上有这个数字的,一律划掉,先划掉所有数字的人赢,输出YES,否则输出NO。
注意坑点:1、每个人只有输或赢一种结果;
2、一开始判定输的人还有可能赢。
【AC代码】
#include<iostream>#include<stdio.h>#include<map>#include<algorithm>#include<math.h>#include<queue>#include<stack>#include<string>#include<cstring>using namespace std;int vis[105];int a[105][105];int p[105][105];int num[105];int b[105];int t[105];int main(){ int i,j,k,s,n,x,tot,tag; scanf("%d",&n); for(i=0;i<n;i++) { memset(p[i],0,sizeof(p[i])); vis[i]=0; scanf("%d",&num[i]); for(j=0;j<num[i];j++) { scanf("%d",&a[i][j]); p[i][a[i][j]]=1; } sort(a[i],a[i]+num[i]); } for(i=0;i<n;i++) { if(vis[i]==1) continue; for(j=0;j<n;j++) b[j]=num[j]; tag=0; tot=0; for(j=0;j<num[i];j++) { for(k=0;k<n;k++) { if(p[k][a[i][j]]) { b[k]--; if(b[k]==0) { tag=1; t[tot]=k; tot++; } } } if(tag) break; } vis[i]=-1; if(tot==1) { vis[t[0]]=1; } else { for(j=0;j<tot;j++) { if(vis[t[j]]==1) continue; vis[t[j]]=-1; } } } for(i=0;i<n;i++) { if(vis[i]==-1) printf("NO\n"); else printf("YES\n"); } return 0;}
- codeforces 370B Berland Bingo(强势模拟)
- CodeForces 370 B.Berland Bingo(模拟)
- CodeForces 370B. Berland Bingo
- B. Berland Bingo----模拟
- Codeforces Round #217 (Div. 2) / 370B Berland Bingo (set_union)
- Codeforces #217 (Div. 2) B. Berland Bingo
- Berland Bingo 【模拟】
- Codeforces Round #217 (diy.2) B. Berland Bingo
- Codeforces 370B Berland Bingog
- Codeforces Round #Pi (Div. 2) B. Berland National Library (模拟)
- CodeForces 567B Berland National Library 容器模拟
- CodeForces 567B Berland National Library(模拟)(简单)
- Codeforces B - Berland National Library
- Codeforces 691A. Fashion in Berland (模拟)
- Code Forces 567 B. Berland National Library(简单模拟)
- CodeForces 638 B.Making Genome in Berland(水~)
- Codeforces Round #Pi (Div. 2)567B Berland National Library(模拟)
- 模拟-CodeForces 370B
- 初学acmer--读《算法竞赛入门经典》笔记(二) p25-27
- 阿里云首推音乐变速短视频SDK,上线抖音 freestyle只需1步
- MySQL数据库性能优化之存储引擎选择
- 虚拟化 cpu的ring0 ring1又是什么概念?
- Spring Cloud学习 -- 配置管理
- codeforces 370B Berland Bingo(强势模拟)
- JVM类加载机制(转载)
- Java设计模式-工厂模式
- android上传库到maven中央
- Android爬坑之旅:软键盘挡住输入框问题的终极解决方案
- 使用CentOS DVD1 和DVD2做本地yum源
- 解决,文件上传到 ftp 服务器,中文出现乱码问题
- 手动卸载office 2010 亲测有效
- EAS 自动获取ID