UVA - 1262 Password(密码)(暴力枚举)
题意:给两个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(密码)(暴力枚举)的更多相关文章
- 【暑假】[数学]UVa 1262 Password
UVa 1262 Password 题目: Password Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- UVA 1262 Password 暴力枚举
Password Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: ...
- UVa 1262 - Password(解码)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Uva 10167 - Birthday Cake 暴力枚举 随机
Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...
- UVA 725 division【暴力枚举】
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...
- 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 ...
- UVA 1262 Password
https://vjudge.net/problem/UVA-1262 字典序第k小 注意两点: 1. k-- 2.去重 #include<cstring> #include<cst ...
- 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 ...
随机推荐
- Django:邮件功能实现
django-users2和django的邮件功能模块都有相关的实现 ----------------------------------------------------------------- ...
- Linux CentOS7 VMware 安装软件包的三种方法、rpm包介绍、rpm工具用法、yum工具用法、yum搭建本地仓库
一.安装软件包的三种方法 Linux下游三种安装方法,rpm工具.yum工具.源码包.rpm按装一个程序包时,有可能因为该程序包依赖另一个程序包而无法安装:yum工具,可以连同依赖的程序包一起安装. ...
- redis-Hash(哈希表)
Redis hash 是一个string类型的field和value的映射表,它的添加.删除操作都是O(1)(平均).hash特别适用于存储对象,将一个对象存储在hash类型中会占用更少的内存,并且可 ...
- Day10 - D - 矿场搭建 HYSBZ - 2730
煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出口,使得无论哪一个挖煤点坍塌之后,其他挖 ...
- 106、Java中String类之使用contains()方法判断子字符串是否存在
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- POJ 3050 Hopscotch 四方向搜索
Hopscotch Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6761 Accepted: 4354 Descrip ...
- lambda表达式-很好---《转载》
Lambda表达式详解 前言 1.天真热,程序员活着不易,星期天,也要顶着火辣辣的太阳,总结这些东西. 2.夸夸lambda吧:简化了匿名委托的使用,让你让代码更加简洁,优雅.据说它是微软自c#1.0 ...
- JavaScript 标识符,关键字和保留字
JavaScript 标识符,关键字和保留字 标识符 标识符(Identifier)就是名称的专业术语.JavaScript 标识符包括变量名.函数名.参数名和属性名. 合法的标识符应该注意以下强制规 ...
- HDU 1024:Max Sum Plus Plus 经典动态规划之最大M子段和
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- EXTjs开发————优雅的用extjs写一个柱状图
简单的写法,extjs可以直接引用插件来写,这里将我发表在百度文库的文档简述下来,有兴趣也可以关注我的百度文库,ID:该用户已失踪. 主要部分的代码: $(document).ready(functi ...