Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Black Vienna
Description This problem is based on the game of Black Vienna. In this version there are three players and 18 cards labeled A-R. Three of the cards are set aside (hidden) and form the "Black Vienna" gang. The remaining cards are shuffled and dealt to the players so that each player has 5 cards. Players never reveal their cards to each other. There is a separate deck of "interrogation cards" which contain three distinct letters in ascending order, like ACG or BHR. Turns rotate through players 1, 2, and 3. On each player's turn, that player selects an interrogation card, puts it face up in front of another player, and that other player must indicate the total number of these cards being held, without saying which ones. All players see the result of the "interrogation". The play continues until a player deduces the three cards in the "gang".
For example, suppose the cards are distributed as follows, and the game then proceeds:
In fact, the game does not need to get to turn 9. With enough thought, player 1 can deduce after turn 8 that the gang is BIK. It is your job to analyse records of games and deduce the earliest time that the gang could be determined for sure. Input The input will consist of one to twelve data sets, followed by a line containing only 0.
The first line of a dataset contains the number, t, of turns reported, 2 ≤ t ≤ 15. The next line contains four blank separated strings for the hands of players 1, 2, and 3, followed by the cards for the gang. The remaining t lines of the data set contain the data for each turn in order. Each line contains three blank separated tokens: the number of the player interrogated, the string of interrogation letters, and the answer provided. All letter strings will contain only capital letters from A to R, in strictly increasing alphabetical order. The same interrogation string may appear in more than one turn of a game. Output There is one line of output for each data set. The line contains the single character "?" if no player can be sure of the gang after all the turns listed. If a player can determine the gang, the line contains the earliest turn after which one or more players can be sure of the answer. Sample Input 9 DGJLP EFOQR ACHMN BIK 2 BJK 0 3 ABK 1 2 DEF 2 2 EIL 1 3 FIP 0 1 GMO 1 2 OQR 3 3 ADQ 1 1 EGJ 2 3 ABCDE FGHIJ KLMNO PQR 3 BKQ 1 1 ADE 3 2 CHJ 2 0 Sample Output 8 ? Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator