跟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. AttributeError: 'dict' object has no attribute 'encode'

    首先这是一个很简单的 运行时错误: 错误分析: AttributeError:属性错误,造成这种错误的原因可能有: 你尝试访问一个不存在的属性或方法.检查一下拼写!你可以使用内建函数 dir 来列出存 ...

  2. 1434:【例题2】Best Cow Fences

    1434:[例题2]Best Cow Fences 时间限制: 1000 ms         内存限制: 65536 KB提交数: 263     通过数: 146 [题目描述] 给定一个长度为n的 ...

  3. [PyTorch] rnn,lstm,gru中输入输出维度

    本文中的RNN泛指LSTM,GRU等等 CNN中和RNN中batchSize的默认位置是不同的. CNN中:batchsize的位置是position 0. RNN中:batchsize的位置是pos ...

  4. [Usaco2009 Nov]lights(高斯消元)

    luogu 点灯游戏应该很多人都在小时候頽过吧 反正我直到现在也不会 很明显一个灯最多只需要点一次 然后高斯消元 解完肯定剩自由元(就是那些全是0的行) 然后这些都爆搜 由于剩下的自由元不会太多 所以 ...

  5. 用SQLyog或Navicat远程连接数据库

    以SQLyog为例(Navicat同理): 登录远程数据库服务器查看当前存在用户:即点击用户管理器(人像图标),查看用户. 1)如果某一用户 主机一栏中是"%",则表示本用户是开放 ...

  6. jenkins构建项目记录1

    jenkins安装见上篇随笔 1.新建任务 2.构建一个自由风格的软件项目 3.源码管理设置 4.构建环境 5.构建 6.构建后操作

  7. Excel OLE控制

    来源:http://blog.csdn.net/chelen_jak/article/details/7069095 Delphi  控制Excel(一) 使用动态创建的方法 首先创建 Excel 对 ...

  8. PHPExcel读取表格内容

    PHPExcel读取表格 先引入类IOFactory.php require_once '../PHPExcel/IOFactory.php'; $filePath = "test.xlsx ...

  9. winform ComboBox/TextBox自动提示

    ComboBox和TextBox控件都带有自动前缀匹配,只要设置其中的AutoCompleteMode,AutoCompleteSource,AutoCompleteCustomSource三个属性的 ...

  10. 2017 计蒜之道 初赛 第一场 A 阿里的新游戏

    题链:https://nanti.jisuanke.com/t/15499 这题观察图纸可知成三线段上的相邻点之间的距离有1,2,3三种情况的,同时要成线段必然是同横坐标或者纵坐标,然后我们排除掉穿过 ...