跟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. winpcap编程设置过滤器之指定获取某个网站的数据

    下面,我将以 乱世隋唐页游 为例,通过编码获取这里面的数据. 游戏图: 我是乱世隋唐的网址是:www.917st.com 这个是官网网址的服务器地址.  42.62.0.14 我玩的游戏服是84区.网 ...

  2. 使用soapUI5.3.0调试webservice接口(参数为XML格式)

    最近项目中经常要调试webservice接口,从朋友处了解到他们经常使用SoapUI,因此学习一下这个工具的使用,为避免遗忘,特地记录下来,分享分享... 下载 #####首先,下载SoapUI,我下 ...

  3. JAVA基础——设计模式之单列模式

    一:单例设计模式 Singleton是一种创建型模式,指某个类采用Singleton模式,则在这个类被创建后,只可能产生一个实例供外部访问,并且提供一个全局的访问点. 单例设计模式的特点: 单例类只能 ...

  4. 牛客网 nowcoder TG test-172

    # solution-nowcoder-172 # A-中位数 $30\%:n\le 200$ 直接枚举 $n-len+1$ 个区间,将这段里的数重新排序直接找到中位数 $60\%:n\le 2000 ...

  5. MySQL异常:Caused by: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request

    Caused by: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or cl ...

  6. KBE实践——登录案例

    目录 服务器 ``` void maini(){ printf("hello world"); } ``` 最小资产库创建 entity配置 实体的Python实现 创建第一个空间 ...

  7. jquery data属性 attr vs data

    html5的自定义data属性相信大家都不会陌生,有了它你可以绑定所需的数据到指定元素上.然后通过jquery设置.获取数据,简直开心的不行啊.想到设置.获取元素属性值,大家一定首先想到了jquery ...

  8. ibdata过大删除的方法

    1.做数据库的逻辑备份 mysqldump -uroot -p123456 -B xx xx xx xx > /backup/all.sql 2.停止mysql进程 service mysqld ...

  9. Python之面向对象函数式编程

    Python之面向对象函数式编程 函数式编程的根本就是用 def 去模拟数学式的编程逻辑. 类似与 y = 2*x + 1 ,当x = 3 时,函数的结果y就得7. def test(x): retu ...

  10. (转载)C++ string中find() ,rfind() 等函数 用法总结及示例

    string中 find()的应用  (rfind() 类似,只是从反向查找) 原型如下: (1)size_t find (const string& str, size_t pos = 0) ...