1. Title Description: Click to open the link
2. Problem-Solving ideas: The topic is a classic decoding problems, according to test instructions, you can find out the common elements of each column in advance, calculate the "gradient" of each column, that is, from a column of the first public letter jumps to the next number of permutations to go through. The password can be rolled out by the gradient. The important note is: 1. When judging public elements, put them in the set beforehand and prevent the elements from being added repeatedly. 2. In order to facilitate subsequent processing of the gradient, the gradient at I can be equal to the number of permutations from column I to the last column. The detailed procedure is shown in the code comment place. (All "attention" is a trap, pit me for a long time only)
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define N 100000int g1[6][5], g2[6][5]; int com[5][6];int cnt[5];int Gre[5];set<int>s[5];int k;void factor () {memset (COM, 0, sizeof (COM)); memset (CNT, 0, sizeof (CNT)); memset (GRE, 0, sizeof), for (int i = 0; i < 5; i++) s[i].clear (); for (int i = 0; i < 5; i++) {Int& num = cnt[i];for (int j = 0; J < 6; J + +) for (int l = 0; l < 6; l++) if (g1[j][i] = = G2[l][i]) S[i].insert (G1[j][i]); /To prevent duplicate elements from being added to the COM array, first pre-store into set}for (int i = 0; i < 5; i++) {int&num = Cnt[i];for (Set<int>::iterator it = s[i].b Egin (); It! = S[i].end (); it++) com[i][num++] = *it;} GRE[4] = cnt[4];//gradient, directly take all permutations for (int i = 3; I >= 0; i--) gre[i] = gre[i + 1] * cnt[i];} int main () {//freopen ("test.txt", "R", stdin), int t;cin >> t;while (t--) {memset (G1, 0, sizeof (G1)); memset (G2, 0, Siz EOF (G2)); Cin >> K;getchar (); for (int i = 0; i < 6; i++) {for (int j = 0; J < 5; j + +) scanf ("%c", &g1[i][j]); GetChar ();} for (int i = 0; i < 6; i++) {for (int j = 0; J < 5; j + +) scanf ("%c", &g2[i][j]); GetChar ();} Factor (); if (k>gre[0]) printf ("no\n"), else{k--;//modified to numbering starting from 0, convenient to calculate int w;for (int i = 0; i < 4; i++) {w = com[i][k/gre[i + 1]];p rintf ("%c", W); k%= gre[i + 1];} w = com[4][k% gre[4]];//The last line is processed separately for printf ("%c\n", W);}} return 0;}
Example 10-8 password UVa1262