UVa 340 Master-mind Hints

Source: Internet
Author: User
Tags cas

Master-mind Hints

MasterMind is a game for the 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 that a code must has and upon the colors that Ma Y occur in a code.

In order to break the code, breaker makes a number of guesses, each guess itself being a code. After each guess Designer gives a hint, stating to what extent the guess matches his secret code.

In this problem you'll be given a secret code and a guess, and is 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 strongif i = J, and is called weak otherwise . Matches (i,J) and (p,Q) is called independent whenI = P if and only if j = Q. A set of matches is called Independent , and all of it members are pairwise independent.

Designer chooses an independent set M of matches for which the total number of matches and the number of strong M Atches is both maximal. The hint then consists of the number of strong followed by the number of weak matches in M. Note that these numbers is uniquely determined by the secret code and the Guess. If the hint turns out to being (n, 0), then the guess was 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, the range 1 T o 9. Following the last guess in each game would be N zeroes; These zeroes is not to be considered as a guess.

Following the data for the first game would appear data for the second game (if any) beginning with a new value for n . The last game in the input would be followed by a single zero (when a value isN would normally be specified). The maximum value for N would be 1000.

Output

The output for each game should list the hints 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 indicating the game number; Games is numbered sequentially starting with 1. Look at the samples below for the exact format.

Sample Input

41 3 5 51 1 2 34 3 3 56 5 5 16 1 3 51 3 5 50 0 0 0101 2 2 2 4 5 6 6 6 91 2 3 4 5 6 7 8 9 11 1 2 2 3 3 4 4 5 51 2 6 1 91 2 2 5 5 5 6 6 6 70 0 0 0 0 0 0 0 0 00

Sample Output

Game 1: (2,0) (    4,0)    Game 2:    (2,4)    (3,2)    (5,0) (    7,0)

Guess number game tips statistics Guess how many numbers are in the correct number of numbers in the answer, but the position is not a single character can only match once

#include <cstdio> #include <algorithm> #include <map>using namespace std;const int N = 1005;int  a[n ], B[n], C, d;int main () {    int N, cas = 0;    while (scanf ("%d", &n), N)    {        map<int, int> AA;        printf ("Game%d:\n", ++cas);        for (int i = 0; i < n; ++i)        {            scanf ("%d", &a[i]);            ++aa[a[i]];        }        while (1)        {            map<int, int> BB;            for (int i = c = d = 0; i < n; ++i)            {                scanf ("%d", &b[i]);                ++bb[b[i]];                if (a[i] = = B[i]) C + +;            }            if (!b[0]) break;            for (int i = 1; I <= 9; ++i)                D + = min (Aa[i], bb[i]);            printf ("    (%d,%d) \ n", C, d-c);}    }    return 0;}


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

UVa 340 Master-mind Hints

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.