340-master-mind hints
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem &problem=276
Mastermind is a game for two players. One of them, Designer, selects a secret code. The other, breaker, tries to break it. A code is no more than a row of colored dots. At the beginning of a game, the players agree upon the length N so a code must have and upon the colors that may occur I n a code.
In order to break the code, breaker makes a number of guesses, each guess itself a code. After each guess Designer gives a hint, stating to what extent the guess of his matches code.
In this problem you are given a secret code and a guess , and are to determine the hint. A hint consists of a pair of numbers determined as follows.
A match is a pair (i,j), and , such . Match (I,J) is called strong where I =j, and is called weak. Two matches (i,j) and (P,Q) are called if i = P if and only if j = Q. A set of matches is called Independent The all of it members are pairwise independent.
Designer chooses a independent set M of matches for which the total number of matches and the number of strong matches AR e both maximal. The hint then consists of the number of strong followed by the number of weak matches in M. Note this these numbers are UN Iquely determined by the secret code and the Guess. If the hint turns out to be (n,0), then the guess are identical to the secret code.
Input
The input would consist of data for a number of games. The input for each game begins with an integer specifying N (the length of the code). Following these would be the secret code, represented as N integers, which we'll limit to the range 1 to 9. There would then follow a arbitrary number of guesses, each also represented as N integers, each in the range 1 to 9. Following the last guess in each game would be N zeroes; These zeroes are do not considered as a guess.
Following the data for the ' the ' the ' the ' the ' the ' game ' appear data for the ' second game (if any) beginning with a new value for N. The last game in the input is followed by a single zero (when a value for N would normally to be specified). The maximum value for N would be 1000.
Output
The output for each game should list the hints of that would is generated for each guess, in order, one hint per line. Each hint should is represented as a pair of integers enclosed in parentheses and separated by a comma. The entire list of hints for each game should is prefixed by a heading the indicating number; Games are numbered sequentially starting with 1. Look in the samples below for the exact format.
Sample Input
4
1 3 5
5
1 1 2 3 4 3 3 5 6 5 5 1 6 1 3 5 1 3 5 5 0 0 0 0 1 2 2 2 4 5 6 6 6 1 2 3 4 5 6 7 8 9 1 1 1 2 2 3------------------3----4-4 5 5 1 2 1 3 1-5 1-
5/>0
Sample Output
Game 1:
(1,1)
(2,0)
(1,2)
(1,2)
(4,0)
Game 2:
(2,4)
(3,2)
(5,0
) (7,0)
Learn English:
1. Match (I,J) is called strong where I =j, and is called weak.
When I=j, a match (I,J) is called a strong match, and vice versa is called a weak match.
2. Two matches (i,j) and (P,Q) are called independent when i = P if and only if j = Q. A set of matches is called Independent The all of it members are pairwise independent.