Password

Time Limit: 3000ms
Memory Limit: 131072KB

This problem will be judged on UVA.
Original ID: 1262

64-bit integer IO format: %lld     
Java class name: Main

[PDF Link]

Shoulder-surfing 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-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 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 x 5 grid. 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 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 piappears
in the i-th column of the grid. In that situation we say that the user password is accepted.

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.

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 p1 p2 p3 p4 p5 appears
in the corresponding column, that can be considered the correct password. So there are many grid configurations 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 x 5grid since there are too
many password candidates. In this 6 x 5 grid space, maximally 65 =
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 configurations 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 configurations for a grid password. The user password is `COMPU', but `DPMAG' is also one candidate password derived from the following configuration.

Figure 3. Both of `COMPU' and `DPMAG' are feasible password .

You are given two configurations 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 first 5 valid password. The first 5 valid passwords are `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 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 of T test cases. The number of test cases T is
given in the first line of the input. The first line of each test case contains one integer, K, 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.

Output

Your 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

3
1
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

Distributed under GPLv3. | Project Homepage | Developer: 51isoft |
Current Style: Cerulean.

/* ***********************************************
Author :CKboss
Created Time :2014年12月15日 星期一 10时08分57秒
File Name :UVA1262.cpp
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath> using namespace std; int k;
char m1[10][10],m2[10][10];
vector<char> vc[10];
vector<string> vs;
char str[10]; void dfs(int deep)
{
if(deep==5)
{
string ans;
for(int i=0;i<5;i++)
ans+=str[i];
vs.push_back(ans);
return ;
}
for(int i=0,sz=vc[deep].size();i<sz;i++)
{
str[deep]=vc[deep][i];
dfs(deep+1);
}
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T_T;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d",&k);
for(int i=0;i<6;i++)
scanf("%s",m1[i]);
for(int i=0;i<6;i++)
scanf("%s",m2[i]); for(int j=0;j<5;j++)
{
vc[j].clear();
for(int i=0;i<6;i++)
{
char c1=m1[i][j];
bool flag=false;
for(int i2=0;i2<6&&flag==false;i2++)
{
if(m2[i2][j]==c1) flag=true;
}
if(flag==true)
{
vc[j].push_back(c1);
}
}
} vs.clear();
dfs(0);
sort(vs.begin(),vs.end());
int tt=unique(vs.begin(),vs.end())-vs.begin();
if(k>tt) puts("NO");
else
{
cout<<vs[k-1]<<endl;
}
} return 0;
}

UVA 1262 Password 暴力枚举的更多相关文章

  1. 紫书 例题 10-8 UVa 1262 (暴力枚举)

    递归一遍遍历所有情况就ok了 #include<cstdio> #include<cstring> #define REP(i, a, b) for(int i = (a); ...

  2. 【暑假】[数学]UVa 1262 Password

    UVa 1262  Password 题目: Password   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld ...

  3. 紫书 例题 10-2 UVa 12169 (暴力枚举)

    就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...

  4. UVA - 1262 Password(密码)(暴力枚举)

    题意:给两个6行5列的字母矩阵,找出满足如下条件的“密码”:密码中的每个字母在两个矩阵的对应列中均出现.给定k(1<=k<=7777),你的任务是找出字典序第k小的密码.如果不存在,输出N ...

  5. UVa 1262 - Password(解码)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. uva 725 DIVISION (暴力枚举)

    我的56MS #include <cstdio> #include <iostream> #include <string> #include <cstrin ...

  7. UVA 1262 Password

    https://vjudge.net/problem/UVA-1262 字典序第k小 注意两点: 1. k-- 2.去重 #include<cstring> #include<cst ...

  8. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  9. UVA 10012 How Big Is It?(暴力枚举)

      How Big Is It?  Ian's going to California, and he has to pack his things, including his collection ...

随机推荐

  1. 14、Django实战第14天:列表筛选功能

    今天完成的是点击这些条件进行机构的筛选 首先来完成城市:当用户点击城市的时候,我们自动给它加一个参数(city.id) 编辑organization.views.py 刷新页面,发现筛选功能已经OK了 ...

  2. C++—揭秘大牛博客一些不同凡人的写法

    天下之大,无奇不有,C++也是这样,今天小编来盘点几个有意思的代码,看看你认识几个?以后见到之后千万别装不认识. 一.基础篇——不一样的输出 1.cerr 输出 cout和cerr究竟有什么不同?这也 ...

  3. struts2中css,js等资源无效 非路径问题(新手问题)

    一个小小的Strust2例子 然后发现css,js,图片用不了,debugger下发现无法访问这些资源(404错误),妈的,那个例子明明可以的,起码从书上的图片看. 发现是web.xml中的过滤器的问 ...

  4. 【暴力】UVALive - 4882 - Parenthesis

    就不断地扫整个序列,如果发现多余的括号就删除.大概复杂度还是O(n²)左右.如何判断不合法请详见代码. To a computer, there is no difference between th ...

  5. 【平面图】【最小割】【最短路】【Heap-Dijkstra】bzoj1001 [BeiJing2006]狼抓兔子

    http://wenku.baidu.com/view/8f1fde586edb6f1aff001f7d.html #include<cstdio> #include<queue&g ...

  6. 【二分答案】bzoj1639 [Usaco2007 Mar]Monthly Expense 月度开支

    #include<cstdio> using namespace std; #define N 100001 int n,m,a[N]; bool check(int x) { int n ...

  7. 【费用流】bzoj3280 小R的烦恼

    类似bzoj1221 http://www.cnblogs.com/autsky-jadek/p/4174087.html 只不过大学有多个,所以我们另开一个节点汇总所有'S->大学'的边,然后 ...

  8. python3开发进阶-Django框架中form的查看校验方法is_valid()的源码,自定义验证方法

    form表单的校验方法is_valid() 点开我们发现这个函数里面只有两个方法方法,最终返回True or False 我们点进.is_bound属性,里面判断传输的数据不是空和上传文件不是空 点进 ...

  9. [SpringMVC+redis]自定义aop注解实现控制器访问次数限制

    原文:http://www.cnblogs.com/xiaoyangjia/p/3762150.html?utm_source=tuicool 我们需要根据IP去限制用户单位时间的访问次数,防止刷手机 ...

  10. 怎么在windows7系统我的电脑中添加快捷方式

    在我的电脑中添加一些快捷方式,这样不用每次在开始菜单中去找了 2 选择开始菜单运行 3 输入:Regedit命令 4 进入路径地址:HKEY_LOCAL_MACHINE\SOFTWARE\Micros ...