Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
Language:
GHOST
Time Limit: 1000MSMemory Limit: 30000K
Total Submissions: 240Accepted: 38

Description

GHOST is a spelling game played by bored school kids on long car/bus rides. The purpose of the game it to accumulate letters that spell some word without ever actually finishing a word.Before the game begins, players agree on the order in which they will play. Plays proceed from one player to the next, returning then to the first player until the game is completed. Each player must, in turn, 1) extend the current "word", 2) bluff, or 3) challenge.
  1. The most common play is to extend the current sequence of letters by adding a single letter, so that the resulting sequence of letters forms the beginning of some word. For example, the first player might call "P", thinking (secretly) of the word "part". The second player might call "L", thinking of the word "play". The third player might call "E", thinking of the word "please".
    A player loses if they actually complete a valid English word of 4 or more letters. For example, if there were only three players, after "PLE" the first player might try to extend the word by calling "A", thinking of the word "plead". This would, however, be a losing play because "plea" is a valid word.
  2. A player who cannot think of a valid letter to extend the current sequence may opt to "bluff" by calling out an arbitrary letter, hoping that the next player will not notice.
  3. Finally, if a player believes, on his turn, that the preceding player was bluffing or that the preceding player completed a word, he may challenge the preceding player. If all players agree that the current sequence completes a word (of at least 4 letters), the preceding player loses. If the preceding player cannot name a word that can be formed from the current sequence, the preceding player loses. If the current sequence is not a valid word and the preceding player is able to name a possible word beginning with the sequence, the challenger loses.

Write a program to serve as a player in a game of GHOST. Note that a skillful player will, on her turn, not only worry about coming up with a legal extension to the current sequence of letters, but will also think about all the words that could be formed from an extension and whether, comparing the number of letters in those words to the number of players, consider whether a possible extension could result in her getting stuck on a future turn with no legal extension that does not end a word, thus losing the game.

Input

The input for this game will consist of a sequence of one or more scenarios.
Each scenario contains the following:
The first line of the scenario will contain a single integer indicating the number of players in the game. This value will be at least 2 for a valid scenario. The end of the input file will be indicated by a value less than 2 for this number.
Following this will be a list of words to serve as the program's dictionary/vocabulary for the scenario. Each word will appear on a separate line, with no leading, trailing, or internal whitespace. Each word will consist only of the characters {a–z}. The end of this list of words will be signaled by an empty line.
Following that empty line, the final input line of the scenario will contain the current sequence of letters, again with no leading or trailing spaces. This sequence may be empty if the computer player is the first player. The sequence may also contain more letters than the number of players, indicating that all players (including the computer player) have taken one or more turns.

Output

Your program will produce a single line of output for each scenario.
That line of output will consist of the current sequence of letters from the input, followed by a single blank, followed by:
  1. The word "Challenge" if the current sequence is a complete word in the vocabulary list or is not a prefix of any word in the vocabulary list, or
  2. A single character representing a valid extension if it can find some word formed with that extension such that this extension does not complete a word and, if all other players continue to spell out that same word, neither that word nor any shorter word would be completed on the computer player's turn.
    If multiple such extensions are possible, and if any extensions guarantee a different player will lose, the program should select the smallest one of those (a < b < ... < z).
  3. The word "Bluff" if the only possible extensions would lead to a loss by the computer player.

Sample Input

3
area
arched
apple
apply
applied

ar
2
area
arch
apple
apply
applied
applying

a
2
area

ax
0

Sample Output

ar e
a p
ax Challenge

Hint

1。如果有必胜的选择,也就是选了某个extension之后,任何以这个extension构成的单词都会导致这个人赢,那肯定先选这种,如果有多个都满足,选最小的那个
2。如果没有上面那种必胜的,那就选可能胜的,也就是以这个extension构成的单词,有的会让他赢,有的会让它输,如果有多种这样的,也选最小的
3。最后如果没有上两种,就只好bluff了

Source

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

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator