UVA

来源:互联网 发布:网易广州网签数据 编辑:程序博客网 时间:2024/06/15 20:52
Shoulder-surfig is the behavior of intentionally and stealthily watching the screen of another person’s
electronic device, such as laptop computer or mobile phone. Since mobile devices prevail, it is getting
serious to steal personal information by shoulder-surfig.
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 knows what we have typed. So it is desirable to
conceal the input information to discourage shoulder-surfers around us. Let me explain one way to do
this.
You are given a 6 × 5grid. Each column can be 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 that each wheel contains the 26 upper letters of English alphabet.
See the following Figure 1.
Figure 1. 6 × 5window clips a valid grid representation for a password.
Assume that we have a length-5 password such as p 1 p 2 p 3 p 4 p 5. In order to pass the authentication
procedure, we should construct a confiuration of grid space where eachp iappears in the i-th column
of the grid. In that situation we say that the user password is accepted.
Figure 2. A valid grid
representation for password
‘COMPU’.
Let me start with one example. Suppose that our password was
set ‘COMPU’. If we construct the grid as shown in Figure 2 on next
page, then the authentication is successfully processed.
In this password system, the position of each password character in each column is meaningless. If each of the 5 characters in
p 1p 2p 3p 4p 5appears in the corresponding column, that can be
considered the correct password. So there are many grid confiurations allowing one password. Note that the sequence of letters
on each wheel is randomly determined for each trial and for each
column. In practice, the user is able to rotate each column and
press “Enter” key, so a should-surfer cannot perceive the password
by observing the 6 × 5grid since there are too many password candidates. In this6 × 5 grid space, maximally 6 5 = 7 , 776 cases are
possible. This is the basic idea of the proposed password system
against shoulder-surfers.
Unfortunately there is a problem. If a shoulder-surfer can observe more than two grid plate confiurations for a person, 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 two observed confiurations for a grid password. The user password
is ‘COMPU’, but ‘DPMAG’ is also one candidate password derived from the following confiuration.
Figure 3. Both of ‘COMPU’ and ‘DPMAG’ are feasible password .
You are given two confiurations of grid password from a shoulder-surfer. Suppose that you have
succeeded to stealthily record snapshots of the target person’s device (e.g. smart phone). Then your
next task is to reconstruct all possible passwords from these two snapshots. Since there are lots of
password candidates, you are asked for the k-th password among all candidates in lexicographical
order. In Figure 3, let us show the fist 5 valid password. The fist 5 valid passwords are ‘ABGAG’ ,
‘ABGAS’, ‘ABGAU’, ‘ABGPG’ and ‘ABGPS’.
The number k is given in each test case diffrently. If there does not exist ak-th password sincek
is larger than the number of all possible passwords, then you should print ‘NO’ in the output.
Input
Your program is to read from standard input. The input consists ofT test cases. The number of test
cases T is given in the fist line of the input. The fist line of each test case contains one integer,K,
the order of the password you should fid. Note that 1 K7, 777. Next the following 6 lines show
the 6 rows of the fist grid and another 6 lines represent the 6 rows of the second grid.
Output
Your program is to write to standard output. Print exactly thek-th password (including ‘NO’) in one
line for each test case.
The following shows sample input and output for three test cases.
Sample Input
31
AYGSU
DOMRA
CPFAS
XBODG
WDYPK
PRXWO
CBOPT
DOSBG
GTRAR
APMMS
WSXNU
EFGHI
5
AYGSU
DOMRA
CPFAS
XBODG
WDYPK
PRXWO
CBOPT
DOSBG
GTRAR
APMMS
WSXNU
EFGHI
64
FGHIJ
EFGHI
DEFGH
CDEFG
BCDEF
ABCDE
WBXDY
UWYXZ
XXZFG
YYFYH
EZWZI
ZGHIJ
Sample Output
ABGAG
ABGPS

NO


水题,暴力即可。


#include <iostream>#include <iomanip>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <deque>#include <string>#include <cmath>#include <vector>#include <utility>#include <set>#include <map>#include <climits>//#pragma comment(linker, "/STACK:1024000000,1024000000")#define pi acos(-1.0)#define INF 2147483647using namespace std;typedef long long ll;typedef pair<int,int > P;int i,j,k,t,n,m,l;char s1[10][10],s2[10][10];vector <char> v[10];bool cmp(const char &a,const char &b){    return a<b;}int main(){    int t;    scanf("%d",&t);    while(t--)    {        for(i=0; i<10; i++)            v[i].clear();        memset(s1,0,sizeof(s1));        memset(s2,0,sizeof(s2));        scanf("%d",&n);        for(i=0; i<6; i++)            for(j=0; j<5; j++)            {                char c;                cin>>c;                s1[i][j]=c;            }        for(i=0; i<6; i++)            for(j=0; j<5; j++)            {                char c;                cin>>c;                s2[i][j]=c;            }        for(j=0; j<5; j++)            for(i=0; i<6; i++)            {                char c=s1[i][j];                for(k=0; k<6; k++)                    if(s2[k][j]==c)                    {                        int z;                        for( z=0;z<v[j].size();z++)                            if(v[j][z]==c)                            break;                        if(z>=v[j].size())                        v[j].push_back(c);                    }            }        for(i=0; i<5; i++)        {            sort(v[i].begin(),v[i].end(),cmp);            //cout<<v[i].size()<<endl;        }        string s;        s.clear();        int num=0;        for(int n0=0; n0<v[0].size(); n0++)        {            s[0]=v[0][n0];            for(int n1=0; n1<v[1].size(); n1++)            {                s[1]=v[1][n1];                for(int n2=0; n2<v[2].size(); n2++)                {                    s[2]=v[2][n2];                    for(int n3=0; n3<v[3].size(); n3++)                    {                        s[3]=v[3][n3];                        for(int n4=0; n4<v[4].size(); n4++)                        {                            num++;                            s[4]=v[4][n4];                            if(num==n)                            {                                for(i=0;i<5;i++)                                cout<<s[i];                                cout<<endl;                                goto jump;                            }                        }                    }                }            }        }        if(num<n)            cout<<"NO"<<endl;        jump:1;    }    return 0;}





原创粉丝点击