超级密码(BFS)
Problem Description
密码是一个C进制的数,并且只能由给定的M个数字构成,同时密码是一个给定十进制整数N(0<=N<=5000)的正整数倍(如果存在多个满足条件的数,那么最小的那个就是密码),如果这样的密码存在,那么当你输入它以后门将打开,如果不存在这样的密码......那就把门炸了吧.
注意:由于宝藏的历史久远,当时的系统最多只能保存500位密码.因此如果得到的密码长度大于500也不能用来开启房门,这种情况也被认为密码不存在.
Input
注意:在给出的M个数字中,如果存在超过10的数,我们约定用A来表示10,B来表示11,C来表示12,D来表示13,E来表示14,F来表示15.我保证输入数据都是合法的.
Output
注意:构成密码的数字不一定全部都要用上;密码有可能非常长,不要试图用一个整型变量来保存密码;我保证密码最高位不为0(除非密码本身就是0).
SampleInput
3
22 10
3
7 0 1 2 10
1
1 25 16
3
A B C
SampleOutput
110
give me the bomb please
CCB
kuangbin搜索好像有个类似的题目,也是找只能由几个数构成某个数的倍数,不同的是那个题只能有01构成而且有SPJ,这道题是输入且输出字典序最小的。
做题历程=7=,最开始思路错了去从n的倍数开始搜TLE,然后正确的思路没有判断取模时0的情况RE,再然后没有把char换成intWA,=7=简直了
思路就是从给定的几个数开始搜索,然后每次加上那几个数,取模判重一下就行了。
值得注意的是因为涉及到进制,一定要注意字母和数字之间的转换。
代码:
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <deque>
#include <queue>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <bitset>
#include <ctime>
#include <fstream>
#include <limits.h>
#include <numeric> using namespace std; #define F first
#define S second
#define mian main
#define ture true #define MAXN 1000000+5
#define MOD 1000000007
#define PI (acos(-1.0))
#define EPS 1e-6
#define MMT(s) memset(s, 0, sizeof s)
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef stringstream sstm;
const int INF = 0x3f3f3f3f; map<int,int>mp,vis;
int n,k,m; int Mod(string x){
int res = ;
for(int i = ; i < x.size(); i++){
res *= k;
if(isdigit(x[i])){ //WA那次就是这里忘记转换数字了=7=
res += x[i] - '';
}
else{
res += x[i] - 'A' + ;
}
res %= n;
//cout << res << " ";
}
return res;
} int bfs(){
queue<string>q;
for(int i = ; i <= ; i++){
if(mp[i]){
string a = "";
a = a + char(i>=?char('A'+i-):char(''+i)); //注意转换
int flag = Mod(a);
if(flag == ){
cout << a << endl;
return ;
}
else{
if(vis[flag] == ){
vis[flag]++;
q.push(a);
//cout << a << " " << a.size() << " " << flag << endl;
}
}
}
}
while(!q.empty()){
string tp = q.front();
q.pop();
if(tp.size() >= ){
return -;
}
for(int i = ; i <= ; i++){
if(mp[i]){
string nxt = tp;
nxt = nxt + char(i>=?char('A'+i-):char(''+i));
int flag = Mod(nxt);
if(flag == ){
cout << nxt << endl;
return ;
}
else{
if(vis[flag] == ){
vis[flag]++;
q.push(nxt);
//cout << nxt << " " << nxt.size() << " " << flag <<endl;
}
}
}
}
}
return -; } int main(){
ios_base::sync_with_stdio(false);
cout.tie();
cin.tie();
int t;
cin>>t;
while(t--){
mp.clear();
vis.clear();
cin>>n>>k>>m;
for(int i = ; i < m; i++){
char tp;
cin>>tp;
if(isdigit(tp)){
mp[tp - '']++;
}
else{
mp[tp - 'A' + ]++;
}
}
if(n == ){ //特判n为0的情况
if(mp[]){
cout << << endl;
continue;
}
else{
cout << "give me the bomb please" << endl;
continue;
}
}
if(bfs() == -){
cout << "give me the bomb please" << endl;
}
}
return ;
}
超级密码(BFS)的更多相关文章
- hdu.1226.超级密码(bfs)
超级密码 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 超级密码(bfs)
超级密码 Time Limit : 20000/10000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- hdu_1226超级密码(BFS)
超级密码 Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息:密码是 ...
- HDOJ 1226 超级密码(bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1226 思路分析:题目要求寻找一串长度不大于500的C进制的密码,且该密码需要为十进制数N的整数倍. & ...
- hdu1226 超级密码 (BFS,里面用了大数取余原理)
Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息: 密码是一个C进 ...
- HDU1226:超级密码(BFS)
Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息: 密码是一个C进 ...
- HDU 1226 超级密码(BFS) (还需研究)
Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Desc ...
- hdu1226超级密码 bfs
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1226/ 题目大意是:寻找一个五百位之内的C进制密码,该密码是N的正整数倍,而且只能用给定的数构成密码,求这样的密 ...
- 超级密码 hdu1226 bfs
超级密码 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU 1226 超级密码(数学 bfs)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1226 超级密码 Time Limit: 20000/10000 MS (Java/Others) ...
随机推荐
- kvm 内部错误:无法找到适合 x86_64 的模拟器
0x00 问题 安装完 KVM 之后,启动管理工具报错:内部错误:无法找到适合 x86_64 的模拟器 于是查看 libvirtd 服务状态,查看到以下内容: 6月 14 10:18:53 local ...
- 云上RDS架构
概述 越来越多的企业选择上云,最基础的云服务就是IaaS(Infrastructure as a Service)服务,直观理解就是虚拟主机,用户不用再自建机房,自己购买服务器,而是直接向云厂商购买虚 ...
- spring-boot-plus快速快发脚手架简介
Everyone can develop projects independently, quickly and efficiently! Introduction spring-boot-plus是 ...
- poi使用随笔
HSSFworkbook,XSSFworkbook,SXSSFworkbook区别简述 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls: XSSFWor ...
- 由group by引发的sql_mode的学习
前言 在一次使用group by查询数据库时,遇到了问题.下面先搭建环境,然后让问题复现,最后分析问题. 一 问题复现 mysql版本 建表插入数据 表的结构 现在问题来了:我想查询上面表中每个部门年 ...
- 03 requests模块基础
1. requests 模块简介 什么是requests 模块 requests模块是python中原生的基于网络请求的模块,功能强大,用法简洁高效.在爬虫领域中占据着半壁江山的地位.requests ...
- 使用MTA HTML5统计API来分析数据
使用MTA HTML5统计API来分析数据 在开发个人博客的时候,用到了腾讯移动分析(MTA),相比其他数据统计平台来说我喜欢她的简洁高效,易上手,同时文档也比较全面,提供了数据接口供用户调用. 在看 ...
- pringboot pom文件引入本地jar包和对其打jar包
maven引入本地jar包需要在pom文件中天剑如下配置: <dependency> <groupId>com.baidu</groupId> <artifa ...
- mybatis对象的插入
或者: 传入JAVA对象 mapper接口代码: public int findUserList(User user); xml代码: <select id="findUserList ...
- 学会了这些技术,你离BAT大厂不远了
每一个程序员都有一个梦想,梦想着能够进入阿里.腾讯.字节跳动.百度等一线互联网公司,由于身边的环境等原因,不知道 BAT 等一线互联网公司使用哪些技术?或者该如何去学习这些技术?或者我该去哪些获取这些 ...
