跟POJ 1465 multiple 类是。仅仅只是多了2个条件,长度不能超过500。还有就是 可能不是十进制。

bfs+同余定理,就是用 mod 来判重。

G++ 15ms

每次枚举一位,然后记录下路径然后输出就能够。

此题坑点 当n==0 的时候 假设 m个数中有0 那么答案就是0 假设没有0 就是give me the bomb please

这儿坑了我好几次。

#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<vector>
#include<cmath> #define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define PI 3.141592654
#define CLR(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,n) for(int i= a;i< n ;i++)
#define FOR0(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define acfun std::ios::sync_with_stdio(false) #define SIZE 500+1
using namespace std; int n,c,m;
int a[17]; struct lx
{
int x,mod;
int len;
int path;
void init(int xx,int mm,int ll,int pp)
{
x=xx,mod=mm,len=ll,path=pp;
}
}q[5001]; void bfs()
{
int h=0,e=0;
bool vis[5001];
CLR(vis,0);
lx tmp;
tmp.init(-1,0,0,-1);
q[h++]=tmp;
while(e<h)
{
tmp=q[e++]; if(tmp.mod==0&&tmp.x!=-1)
{
stack<char>out;
while(tmp.path!=-1)
{
char temp;
if(tmp.x<10&&tmp.x>=0)
temp=tmp.x+'0';
else
temp=tmp.x-10+'A';
out.push(temp);
tmp=q[tmp.path];
}
while(!out.empty())
{
printf("%c",out.top());
out.pop();
}
printf("\n");
return;
} FOR(k,0,m)
{
int num=tmp.mod*c+a[k];
int mod=num%n;
if(a[k]==0&&tmp.len==0)continue;
if(vis[mod]||tmp.len>=500)continue;
lx now;
vis[mod]=1;
now.init(a[k],mod,tmp.len+1,e-1);
q[h++]=now;
}
}
puts("give me the bomb please");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&c,&m);
FOR(i,0,m)
scanf("%X",&a[i]);
sort(a,a+m);
if(n==0)
{
if(a[0]==0)
puts("0");
else
puts("give me the bomb please");
continue;
}
bfs();
}
}

HDU 1226 超级password的更多相关文章

  1. hdoj 1226 超级password 【隐图BFS】

    称号:hdoj 1226 超级password 分析:这题属于隐式图搜索,状态不是非常明显,须要自己建立. 事实上搜索说白了就是暴力. 这个题目就是,首先对给出的能够组成的全部的数依次枚举.长度从小到 ...

  2. HDU 1226 超级密码(数学 bfs)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1226 超级密码 Time Limit: 20000/10000 MS (Java/Others)    ...

  3. HDU 1226 超级密码 (搜素)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1226 题意简单,本来是一道很简单的搜素题目. 但是有两个bug: 1.M个整数可能有重复的. 2.N可 ...

  4. hdu.1226.超级密码(bfs)

    超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  5. hdu 1226 超级密码

    超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem D ...

  6. hdu 1226 超级密码(bfs+余数判重)

    题意:略过 分析:用m个数字组成一个能够被n整除的c进制数的最小值,实际上本题的关键就在于这个最小值上.  首先确定我们的思路是从小到大寻找.先查看一位数,即查看着m个数字是否能被n整除:若不能,就查 ...

  7. HDU 1226 超级密码(BFS) (还需研究)

    Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Desc ...

  8. HDOJ 1226 超级密码(bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1226 思路分析:题目要求寻找一串长度不大于500的C进制的密码,且该密码需要为十进制数N的整数倍. & ...

  9. hdu 1226 BFS + bfs记录路径

    http://acm.hdu.edu.cn/showproblem.php? pid=1226 为了节省空间.您可以使用vis初始化数组初始化-1. 发现BFSeasy错了地方 始一直WA在这里:就是 ...

随机推荐

  1. vue工程化之去除Eslint验证

    有的时候用vue-cli创建好项目之后,写代码时会出现换行和空格报错,出现这么写错误是什么原因呢? 相信第一次接触时有点摸不着头脑.其实是在你用vue-cli脚手架构建项目时用了ESLint代码检查工 ...

  2. 在vue中场景,循环行,点击当前行编辑数据

    当前列表 点击编辑,行变为编辑框. <Row style="color:#999;margin-bottom:11px"> <Row style="ma ...

  3. 第2节 mapreduce深入学习:9、手机上行流量排序

    还是上次那个例子,需求二:上行流量倒序排序(递减排序) 分析,以需求一的输出数据作为排序的输入数据,自定义FlowBean,以FlowBean为map输出的key,以手机号作为Map输出的value, ...

  4. thinkphp5中vendor的使用?

    1.创建处理数组的类ArrayList.php <?php /** * ArrayList实现类 * @author liu21st <liu21st@gmail.com> */ c ...

  5. 零基础入门学习Python(4)--改进我们的小游戏

    前言 在以前的博客中有做个一个小游戏,但是太简单了,所以这次就来对我们做的小游戏进行改进,改善从以下四个方面进行: 程序猜错的时候要给出提示,例如告诉用户输入的值是大了还是小了. 以前程序每运行一次只 ...

  6. Java 集合相关

    对整个体系做一个记录,并不涉及详细应用 Object类 1. 重写toString方法 System.out.println可以打印任何对象在于Object类拥有一个方法 public String ...

  7. UvaLive 4917 Abstract Extract (模拟)

    题意: 给定一篇文章, 文章中有段落, 段落中有句子. 句子只会以'!' , '.' , '?' 结尾, 求出每段中含有与他下面同样是该段落中相同单词数最多的句子, 注意, 单词忽略大小写, 重复的单 ...

  8. //……关于promise

    什么是promise? promise 翻译成中文的意思是 "承诺" ,一个承诺说出去了说明他是进行中的,承诺兑现了代表成功,没有兑现代表失败了. promise 对象的状态一旦发 ...

  9. 【Kafka问题解决】Connection to xxx could not be established. Broker may not be available.

    请检查Kafka的config/server.properties 看看是否有填写 listeners=PLAINTEXT://kafka-host:9092 advertised.listeners ...

  10. 60. Spring Boot写后感【从零开始学Spring Boot】

    从2016年4月15日到2016年7月20日经历长达3个月的时间,[从零开始学习Spring Boot]系列就要告一段落了.国内的各种资源都比较乱或者是copy 来copy去的,错了也不加以修正下,导 ...