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 ...
随机推荐
- MariaDB——数据库集群
Mariadb数据库集群 mariadb主从 主从多用于网站架构,因为主从的同步机制是异步的,数据的同步有一定的延迟性,也就是说可能会导致数据丢失,但是性能比较好,因此网站大多数 用的是主从架构的数据 ...
- vue 移动端屏幕适配
https://github.com/evrone/postcss-px-to-viewport/blob/master/README_CN.md基本配置 // eslint-disable-next ...
- uWSGI, Thread, time.sleep 使用问题
下面的问题,在flask程序独立运行中,都没有问题,但是部署在 uwsgi 上表现异常: 1. 在http请求处理过程中,产出异步线程,放在线程池中,线程的启动时间有比较明显的延迟. 2. 在异步线程 ...
- 使用Go语言一段时间的感受
作者 openkk 2012-03-04 18:26:58 文/Windstorm 有一段时间没更新了.最近在忙一个 Server+Client 的项目,Client 是 Android 手机,大概也 ...
- P1073 多选题常见计分法
P1073 多选题常见计分法 转跳点:
- phpStudy隐藏后门预警
1.事件背景 近日,使用广泛的PHP环境集成程序包phpStudy被公告疑似遭遇供应链攻击,程序包自带PHP的php_xmlrpc.dll模块隐藏有后门,安恒应急响应中心和研究院随即对国内下载站点提供 ...
- Azure Cognitive Services- Speech To Text
Speech 服务是认知服务的一种,提供了语音转文本,文本转语音, 语音翻译等,今天我们实战的是语音转文本(Speech To Text). STT支持两种访问方式,1.是SDK,2.是REST AP ...
- 008-PHP定义数组
<?php /*定义数组$Cities[]*/ $Cities[0] = "北京"; $Cities[1] = "天津"; $Cities[2] = &q ...
- vue axios的跨域前后端解决方案
原因出于安全考虑,浏览器有一个同源策略.浏览器中,异步请求的地址与目标地址的协议.域名和端口号三者与当前有不同,就属于跨域请求. 限制跨域访问是浏览器的一个安全策略,因为如果没有这个策略,那么就有被跨 ...
- php5.3不支持 ereg、ereg_replace等函数问题
在php5.3环境下运行oscommerce,常常会出现Deprecated: Function ereg() is deprecated in...和Deprecated: Function ere ...