Traditional BINGO
InterviewTime limit1sMemory limit128 MB
For each card, find how many announced numbers are needed before some row, column, or diagonal of five spaces is fully marked, with the center free.
- Level
Easy3 of 10
- Topics
- Simulation, Array, Implementation, Brute force
- Solved
- No attempts yet
Problem
Traditional BINGO is played in person in a large hall. Players gather, pay an entry fee, and then the games begin. A night of BINGO consists of many games played continuously, one after another.
A single BINGO game works like this. Each player holds one or more BINGO cards (a player may play any number of cards). Every card has 5 rows and 5 columns, giving 25 spaces.
The columns are labeled, from left to right, with the letters B, I, N, G, and O. With one exception — the center space is "free" — every space holds a number, assigned as follows:
- Each space in the
Bcolumn holds a number from 1 to 15. - Each space in the
Icolumn holds a number from 16 to 30. - Each space in the
Ncolumn holds a number from 31 to 45. - Each space in the
Gcolumn holds a number from 46 to 60. - Each space in the
Ocolumn holds a number from 61 to 75.
A number may appear at most once on a single card.
A sample BINGO card:
The number of distinct BINGO cards is very large:
// the B, I, G, and O columns * the N column
(15 * 14 * 13 * 12 * 11) ^ 4 * (15 * 14 * 13 * 12)
Interesting to a statistician, perhaps, but this count has nothing to do with a player's chances of winning.
There are 75 possible BINGO numbers in total:
B1, B2, B3, ... B15, I16, I17, ... I30, N31, N32, ... O74, O75
Each number is painted on a ball inside a large rotating bin. The announcer spins the bin, draws a ball, and announces its number. Every player checks all of their cards; if the number appears on a card, that space is marked. The center FREE SPACE may be marked at any time (treat it as always marked).
When a player has a BINGO — five marked spaces in a single row, column, or diagonal — that player calls out "BINGO". The card is verified, and if it is a genuine winner the game stops. Every BINGO game runs until someone wins.
Input
The first line contains , the number of BINGO games to analyze. Then game descriptions follow.
Each game description begins with a card, given as five lines (one line per row). Rows 1, 2, 4, and 5 each list 5 numbers; row 3 lists only 4 numbers, because its center space is the free space.
After the card, one or more lines list some ordering of all 75 BINGO numbers — the exact sequence in which they are announced. Every value is an integer from 1 to 75 (the single-letter column prefix is redundant and is omitted).
Assume the card holder is the only player and plays only this one card, so the game ends the moment this card first makes a BINGO.
Output
For each game, print one line:
BINGO after N numbers announced
where is the number of announced numbers at the moment the card first achieves a BINGO — a full row, column, or diagonal, with the free center space always counting as marked.
Hint
Chances of Winning
Every BINGO game has a winning card, so a player's chance of winning depends on how many cards are in the game and how many of them that player holds. For example, a player holding 12 cards in a game with 1200 cards has a 1 in 100 chance of winning.