题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1226

题意简单,本来是一道很简单的搜素题目。

但是有两个bug:

1、M个整数可能有重复的。

2、N可能为0。

你说这两个bug有意思么,特别是第二个,真没意思。

AC代码::

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <ctime>
#pragma comment(linker, "/STACK:16777216")
using namespace std; typedef __int64 LL;
const int N=5005;
const int M=555555;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-7; int n,c,m;
int h[27];
bool vis[N];
struct xh
{
int left,step;
string s;
}w,e; int char_int(char k)
{
if(k<='9')
return k-'0';
return k-'A'+10;
} char int_char(int k)
{
if(k<=9)
return k+'0';
return k-10+'A';
} void BFS()
{
int i,t;
memset(vis,0,sizeof(vis));
queue<xh>q;
for(i=0;i<m;i++)
{
if(h[i]==0) continue;
w.left=h[i]%n;
w.s="";
w.s+=int_char(h[i]);
w.step=1;
if(w.left==0)
{
cout<<w.s<<endl;
return ;
}
if(!vis[w.left])
{
q.push(w);
vis[w.left]=1;
}
}
while(!q.empty())
{
e=q.front();
q.pop();
if(e.step>=500)
continue;
for(i=0;i<m;i++)
{
w=e;
w.left=(w.left*c+h[i])%n;
if(vis[w.left]) continue;
vis[w.left]=1;
w.step++;
w.s+=int_char(h[i]);
if(w.left==0)
{
cout<<w.s<<endl;
return ;
}
q.push(w);
}
}
puts("give me the bomb please");
} int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%d%d",&n,&c);
scanf("%d",&m);
int tt[20];
memset(tt,0,sizeof(tt));
for(int i=0;i<m;i++)
{
char k;
cin>>k;
int p=char_int(k);
tt[p]=1;
}
m=0;
for(int i=0;i<16;i++)
if(tt[i])
h[m++]=i;
if(n==0)
{
if(h[0]==0)
puts("0");
else
puts("give me the bomb please");
continue;
}
BFS();
}
return 0;
}

HDU 1226 超级密码 (搜素)的更多相关文章

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

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

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

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

  3. hdu 1226 超级密码

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

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

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

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

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

  6. HDOJ 1226 超级密码

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

  7. HDOJ 1226 超级密码(bfs)

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

  8. HDU 1226 超级password

    跟POJ 1465 multiple 类是.仅仅只是多了2个条件,长度不能超过500.还有就是 可能不是十进制. bfs+同余定理,就是用 mod 来判重. G++ 15ms 每次枚举一位,然后记录下 ...

  9. hdu1226超级密码 bfs

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1226/ 题目大意是:寻找一个五百位之内的C进制密码,该密码是N的正整数倍,而且只能用给定的数构成密码,求这样的密 ...

随机推荐

  1. 自己用h5写的转盘。写贴上来吧。

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. OpenGL框架+QT版

    原地址:http://blog.chinaunix.net/uid-25799257-id-3498005.html 之前一直做地图的算法,没什么时间学习opengl,之前看nehe_OpenGL.c ...

  3. delphi中左右翻转窗体(修改EXStyle)

    unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...

  4. tomcat 后台启动设置

    如果你环境变量配置对了且保证tomcat的bin目录下有如下三个文件,则你只需在cmd中运行 service install tomcat即可将tomcat添加的服务项中,然后在设置开机自动启动,则以 ...

  5. 基于visual Studio2013解决C语言竞赛题之1069链表查找删除

        题目 解决代码及点评 /* 功能:建立一个链表,每个结点包括:学号.姓名.性别.年龄.输入一个年龄,如果链表中的结点所包含的年龄等于此年龄, 将此结点删除,输出最后的链表. 时 ...

  6. phpcms 列表页中,如何调用其下的所有子栏目(或特定的子栏目)?

    {pc:get sql="select * from phpcms_category where catid in(你的子栏目ID)" return="data" ...

  7. 单元测试工具 SmokeTest

    .NET 程序集单元测试工具 SmokeTest Smoke Test(冒烟测试),也称Regression Test(回归测试),是对软件的安装和基本功能的测试.一般地我们使用脚本来实现Smoke ...

  8. find: paths must precede expression(转)

    find: paths must precede expressionUsage: find [-H] [-L] [-P] [path...] [expression] 然后就上网查了一下,结果搜索到 ...

  9. rac各节点实例需设置为相同的一些参数

    RAC Parameters That Require Identical Settings • ACTIVE_INSTANCE_COUNT • ARCHIVE_LAG_TARGET • COMPAT ...

  10. C++基础之二:常量指针和指针常量

    1.常量指针 定义:具有只能够读取内存中数据,却不能够修改内存中数据的属性的指针,称为指向常量的指针,简称常量指针. 声明:const int * p; 注:可以将一个常量的地址赋值给一个对应类型的常 ...