题意:给两个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. 如何在SecureCRT中上传文件到linux服务器上

    1.使用yum安装运行命令sudo yum install lrzsz(默认使没有安装运行命令的) 2.上传命令rz  下载命令sz  

  2. django中添加日志功能

    官方文档 猛戳这里 在settings中配置以下代码 #LOGGING_DIR 日志文件存放目录 LOGGING_DIR = "logs" # 日志存放路径 if not os.p ...

  3. IOS 常用View属性设置

    设置按钮属性 1.设置按钮背景颜色 backgroundColor @property (weak, nonatomic) IBOutlet UIButton *deleteButton; self. ...

  4. OpenResty 实现项目的灰度发布

    1.安装 openresty 依赖模块: [root@Centos opt]# yum -y install pcre-devel openssl openssl-devel postgresql-d ...

  5. mysql多实例双主部署

    本文引自公司技术文档,仅作为记录. 背景 有的时候需要进行数据库环境的隔离,以及节省服务器资源一台mysql安装多个数据库实例,一个实例下构建多个数据库​ 安装mysql yum -y install ...

  6. HTML5学习第四天

    HTML5学习第四天 一.HTML列表 HTML列表,有无序表,有序表以及自定义表,列表于列表之间可以实现嵌套 列表相关操作 <ul> <li>(多选)谁世界第二可爱?< ...

  7. 《机学五》KNN算法及实例

    一.概述 [定义]如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别,则该样本也属于这个类别. 二.距离计算公式 两个样本的距离可以通过如下公式计算,又叫[欧式距 ...

  8. 定义一个共享数据块DB1 在DB1中定义一个数组 用程序 访问数据里面的某一个成员或者地址连续的成员

    提纲 : 定义一个共享数据块 DB1 在DB1 中定义数组 用SFC21 实现 实现全部数组元素的赋一样的值 实现 给数组中的某一个元素赋值 实现 对数组中的全部元素赋值 实现将数组中的某个 或者 某 ...

  9. 数据结构——KMP(串)

    KMP一个非常经典的字符串模式匹配算法,虽然网上有很多kmp算法的博客,但是为了更好的理解kmp我还是自己写了一遍(这个kmp的字符串存储是基于堆的(heap),和老师说的定长存储略有不同,字符串索引 ...

  10. Jenkins实现自动打包,MAVEN打包,Shell脚本启动

    1.点击New任务 2.创建任务,输入项目名 3.输入描述等 4.选择Git或SVN 5.自动,定时打包 6.在Build下配置