UVa 1262 Password
Topic:
Password
Time Limit: 3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format: %lld &%llu |
Submit Status
Description
Shoulder-surfing is the behavior of intentionally and stealthily watching the screens of another person ' s electronic d Evice, such as laptop computer or mobile phone. Since mobile devices prevail, it is getting serious to steal personal information by shoulder-surfing.
Suppose that we have a smart phone. If We touch the screen keyboard directly to enter the password, this is very vulnerable since a shoulder-surfer easily kno WS-We have typed. So it's desirable to conceal the input information to discourage shoulder-surfers around us. Let me explain one-to-do this.
You are given a 6 x 5 grid. Each column can is considered the visible part of a wheel. So you can easily rotate each column wheel independently to make password characters visible. In this problem, we assume it each wheel contains the upper letters of 中文版 alphabet. See the following figure 1.
Figure 1.6 x 5 window clips A valid grid representation for a password.
Assume that we have a length-5 password such as p1 P2 p3 p4 p5. In order to pass the authentication procedure, we should construct a configuration of grid space where each pi appears in the I-th column of the grid. In that situation we say, the user password is accepted.
Let me start with one example. Suppose that we password was set ' Compu '. If we construct the grid as shown. 2 on next page, then the authentication is successfully processed.
Figure 2. A valid grid representation for password ' Compu '.
In this password system, the position of each password character in each column is meaningless. If each of the 5 characters in p 1 p 2 p 3 P 4 P 5 appears in the corresponding column, which can be considered the correct password. So there is many grid configurations allowing one password. Note the sequence of letters on each wheel are randomly determined for each trial and for each column. In practice, the user was able to rotate each column and press ' Enter ' key, so a should-surfer cannot perceive the Passwor D by observing the 6 x 5 grid Since there is too many password candidates. In this 6 x 5 grid space, maximally 65 = 7, 776 cases is possible. This was the basic idea of the proposed password system against shoulder-surfers.
Unfortunately there is a problem. If a shoulder-surfer can observe more than the other grid plate configurations for a person and then the shoulder-surfer can reduce The searching space and guess the correct password. Even though it is not easy to stealthily observe other's more than once, this is one weakness of implicit grid passwords.
Let me show one example with the observed configurations for a grid password. The user password is ' compu ', but ' Dpmag ' was also one candidate password derived from the following configuration.
Figure 3. Both of ' Compu ' and ' dpmag ' are feasible password.
You are given the configurations of the grid password from a shoulder-surfer. Suppose that you had succeeded to stealthily record snapshots of the target person ' s device (e.g. smart phone). Then your next task was to reconstruct all possible passwords from these and snapshots. Since There is lots of password candidates, you is asked for the k-th password among all candidates in Lexi Cographical order. In Figure 3, let us show the first 5 valid password. The first 5 valid passwords is ' abgag ', ' Abgas ', ' Abgau ', ' abgpg ' and ' Abgps '.
The number K is given in each test case differently. If There does not exist a K-th password since k are larger than the number of all possible passwords and then you Should print 'NO' in the output.
Input
Your program was to read from standard input. The input consists of T test Cases. The number of test cases T is given on the first line of the input. The first line of all test case contains one integer, K, and the order of the password you should find. Note that 1K7, 777. Next the following 6 lines show the 6 rows of the first grid and another 6 lines represent the 6 rows of the second grid.
OutputYour Program is-to-write to standard output. Print exactly the
k-th password (including ' NO') in one line for each test case.
The following shows sample input and output for three test cases.
Sample Input
31aygsudomracpfasxbodgwdypkprxwocboptdosbggtrarapmmswsxnuefghi5aygsudomracpfasxbodgwdypkprxwocboptdosbggtrarapmmswsxnuefg Hi64fghijefghidefghcdefgbcdefabcdewbxdyuwyxzxxzfgyyfyhezwzizghij
Sample Output
Abgagabgpsno
Ideas:
decoding and encoding issues. Remove the non-repeating letters to derive the possible set of letters for each position, and then recursively solve the sort. Note
K-=k*m
string is different from char and needs attention when programming.
Code:
1#include <iostream>2#include <string>3#include <vector>4#include <cstdio>5#include <algorithm>//Sort6 #definefor (A,B,C) for (int a= (b);a< (c); a++)7 using namespacestd;8 9 Const intMAXN =6, maxm=5;Ten One intK; Avector<Char>TABLE[MAXM]; - stringans; - the intDfsintd) { - if(D==MAXM)return true; - intm=1; for (i,d+1, MAXM) m *=table[i].size (); -For (K,0, Table[d].size ()) + if(K*m < K && k<=1)*m) { -Ans + =Table[d][k]; +k-=k*m; A returnDFS (d+1); at } - return false; - } - - intMain () { - stringA[MAXN],B[MAXN]; in intT scanf"%d",&T); - while(t--) { toans=""; for (I,0, MAXM) table[i].clear ();//Clear () + -scanf"%d",&K); thefor (I,0, MAXN) cin>>A[i]; *for (I,0, MAXN) cin>>B[i]; $For (J,0, MAXM)Panax Notoginsengfor (I,0, MAXN) for (K,0, MAXN)//make_table - if(a[i][j]==B[k][j]) { the Table[j].push_back (A[i][j]); + Break; A } thefor (I,0, MAXM) sort (Table[i].begin (), Table[i].end ());//Sort + /*For (I,0,MAXM) { - For (J,0,table[i].size ()) $ cout<<table[i][j]; $ cout<<endl; - } - */ the if(Dfs (0)) cout<<ans;Elsecout<<"NO"; -cout<<"\ n";Wuyi } the return 0; -}
"Summer Vacation" [Mathematics]uva 1262 Password