UVA 340-master-mind Hints (stl-map)

Source: Internet
Author: User

Master-mind HintsTime limit:MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatus

Description

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 &NBSP, such that  . Match ( i , J ) is called  strong  when  i  =  J , and is called  weak  otherwise. Matches ( i , J ) and ( p , Q ) are called  Independent  when  i  =  p  if and only if  J  =  q . A set of matches is called  the independent  when all the members of it is 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'll be the secret code, represented as Nintegers, which we'll limit to the range 1 to 9. There would then follow a arbitrary number of guesses, each also represented as Nintegers, each of the range 1 to 9. Following the last guess in each game would be NZeroes; 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 is N 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)

Test instructions: A game, there is an original password, the following n line is the password you guessed, each line if the same column number is the same a++, if the same column corresponds to the same letter, but the other columns have the same, then b++, each number can only be used once, and then output (A, B).

Idea: Use the STL map to record the number of occurrences of each number. Then first find out the same number of each column, then the current number in the original password and the password you gave to find the smallest, and then the smallest minus a is B.

PS: note the output format.

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #include < Iostream> #include <map>using namespace Std;int a[1010];int b[1010];int main () {    int n,i,j;    int t=1;    int a, B;    while (~SCANF ("%d", &n)    } {        if (n==0) break            ;        Map<int,int >q;        printf ("Game%d:\n", t++);        for (i=0;i<n;i++)        {            scanf ("%d", &a[i]);            q[a[i]]++;        }        for (;;)        {            Map<int,int >p;            a=b=0;            for (i=0;i<n;i++)            {                scanf ("%d", &b[i]);                p[b[i]]++;                if (A[i]==b[i])                    a++;            }            if (b[0]==0) break                ;            for (i=1;i<=9;i++)                b+=min (P[i],q[i]);             printf ("    (%d,%d) \ n", a,b-a);        }    }    return 0;}


UVA 340-master-mind Hints (stl-map)

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.