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

分析:因为k<=7777,直接按字典序从小到大的顺序递归一个一个的枚举。

注意:定义在dfs里的vis不能放在全局,否则会导致值的混用。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 30000000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
char pic[2][6][5];
char ans[6];
int k;
int cnt;
bool dfs(int cur){
if(cur == 5){
if(++cnt == k){
ans[cur] = '\0';
return true;
}
return false;
}
int vis[2][26];
memset(vis, 0, sizeof vis);
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 6; ++j){
vis[i][pic[i][j][cur] - 'A'] = 1;
}
}
for(int i = 0; i < 26; ++i){
if(vis[0][i] && vis[1][i]){
ans[cur] = 'A' + i;
if(dfs(cur + 1)) return true;
}
}
return false;
}
int main(){
int T;
scanf("%d", &T);
while(T--){
cnt = 0;
scanf("%d", &k);
for(int i = 0; i < 2; ++i){
for(int j = 0; j < 6; ++j){
scanf("%s", pic[i][j]);
}
}
if(!dfs(0)){
printf("NO\n");
}
else{
printf("%s\n", ans);
}
}
return 0;
}

  

UVA - 1262 Password(密码)(暴力枚举)的更多相关文章

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

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

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

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

  3. UVA 1262 Password 暴力枚举

    Password Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID:  ...

  4. UVa 1262 - Password(解码)

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

  5. Uva 10167 - Birthday Cake 暴力枚举 随机

      Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...

  6. UVA 725 division【暴力枚举】

    [题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...

  7. UVa 10603 Fill [暴力枚举、路径搜索]

    10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...

  8. UVA 1262 Password

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

  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. redis api-hash

  2. Linux centosVMware shell脚本介绍、shell脚本结构和执行、date命令用法、shell脚本中的变量

    一. shell脚本介绍 shell是一种脚本语言 aming_linux blog.lishiming.net 可以使用逻辑判断.循环等语法 可以自定义函数 shell是系统命令的集合 shell脚 ...

  3. vue的高级使用技巧

    全局组件注册 一般组件应用弊端,比较笨拙繁琐低效,比如我们写了一些组件,需要引用上的时候就通过import导入,那如果是高频繁需要使用的组件,则需要在每个使用的时候都需要引入并注册 假设现在有两个组件

  4. spring事务代码实践

    事务一般是指数据库事务,是指作为一个程序执行单元执行的一系列操作,要么完全执行,要么完全不执行.事务就是判断以结果为导向的标准. 一.spring的特性(ACID) (1).原子性(atomicity ...

  5. 用python写测试数据文件

    f是指向文件的指针,r是转义字符,可以让字符串中的\保持不被转义.路径点属性查然后加上当前文件. 'w'表示只写,‘r’表示只读. import random 导入random数 s = []开一个空 ...

  6. 吴裕雄--天生自然JAVA数据库编程:JDBC2.0操作

    import java.sql.Connection ; import java.sql.DriverManager ; import java.sql.SQLException ; import j ...

  7. SciPy 输入输出

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...

  8. tensorflow实现线性模型和sklearn的线性模型比较

    自己用tensorflow实现了linear模型,但是和sklearn提供的模型效果相比,实验结果差了很多,所以尝试了修改优化算法,正则化,损失函数和归一化,记录尝试的所有过程和自己的实验心得. im ...

  9. Day6-T2

    原题目 给你一个长度为n的序列A,请求出最大的一对数(Ai ,Aj),使Ai&Aj最大. 第一行为n,接下来n行,每一个数表示Ai. 输出最大的“and”. S1: Input: Output ...

  10. C# log4net相关配置说明

    添加相关文件到工程 链接: https://pan.baidu.com/s/1o83Juo6 密码: inkg 下载附件, 把里的log4net.dll 和 log4net.config 复制到工程目 ...