Ultraviolet A 340 Master-Mind Hints (optimized search & copy an array)

Source: Internet
Author: User

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 lengthNThat a code must have and upon the colors that may occur in a code.

MatchIs a pair (I,J), And, such that. Match (I,J) Is calledStrongWhenI=J, And is calledWeakOtherwise. Two matches (I,J) And (P,Q) Are calledIndependentWhenI=PIf and only ifJ=Q. A set of matches is calledIndependentWhen all of its members are pairwise independent.

MOf matches for which the total number of matches and the number of strong matches are both maximal. The hint then consists of the number of strong followed by the number of weak matches inM. Note that these numbers are uniquely determined by the secret code and the guess. If the hint turns out to be (N, 0), then the guess is identical to the secret code.

N(The length of the code). Following these will be the secret code, representedNIntegers, which we will limit to the range 1 to 9. There will then follow an arbitrary number of guesses, each also representedNIntegers, each in the range 1 to 9. Following the last guess in each game will beNZeroes; these zeroes are not to be considered as a guess.

N. The last game in the input will be followed by a single zero (when a valueNWocould normally be specified). The maximum valueNWill be 1000.

ExactFormat.

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 1 3 1 5 1 6 1 91 2 2 5 5 5 6 6 6 70 0 0 0 0 0 0 0 0 00

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

I,J) Is calledStrongWhenI=J, And is calledWeakOtherwise.

I,J) And (P,Q) Are calledIndependentWhenI=PIf and only ifJ=Q. A set of matches is calledIndependentWhen all of its members are pairwise independent.

MOf matches for which the total number of matches and the number of strong matches are both maximal.

M.

Count the same number in the same column, and then subtract one from the number corresponding to the same number in the same column.

Statistics 1 ~ 9. The number of occurrences in the two sequences. Each digit is added with a smaller number value in the other two sequences. For details, see the code.

/* 0.019 s */# include <cstdio> # include <cstring> # include <algorithm> using namespace std; int s [1005], g [1005]; int a [15], B [15], c [15]; int main (void) {int cas = 0, n; while (scanf ("% d ", & n), n) {memset (c, 0, sizeof (c); for (int I = 0; I <n; I ++) {scanf ("% d", & s [I]); c [s [I] ++;} printf ("Game % d: \ n ", ++ cas); while (true) {memcpy (a, c, sizeof (c); // tip: use memcpy to assign the number of 1-9 counts in c [] to a [] memset (B, 0, sizeof (B); for (int I = 0; I <n; I ++) {scanf ("% d", & g [I]); B [g [I] ++ ;} if (! G [0]) break; int x = 0, y = 0; for (int I = 0; I <n; I ++) if (s [I] = g [I]) {a [s [I] --; B [s [I] --; x ++ ;} for (int I = 1; I <= 9; I ++) y + = min (a [I], B [I]); printf ("(% d, % d) \ n ", x, y) ;}} return 0 ;}

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.