题目地址: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. Java ArrayList add(int index, E element) example

    Simple add() method is used for adding an element at the end of the list however there is another va ...

  2. QT中.pro文件的写法

    QT中.pro文件的写法   qmake 变量 含义 #xxxx 注释, 从“#”开始,到这一行结束 SOURCES 指定源文件 SOURCES = *.cpp 对于多源文件,可用空格分开 SOURC ...

  3. 教会你如何编写makefile文件

    最近一直在学习makefile是如何编写的.当我们写的程序文件比较少的时候,敲入gcc /g++,当你在大型工程中,在一个个编译文件的话,你可能就会很郁闷.linux有一个自带的make命令,它让你的 ...

  4. 【 .NET 面向对象程序设计进阶》】【 《.NET 面向对象编程基础》】【《正则表达式助手》】

    <.NET 面向对象程序设计进阶> <.NET 面向对象程序设计进阶> <正则表达式助手>

  5. WindowsPhone8中实现圆形图片的生成显示

    原文 WindowsPhone8中实现圆形图片的生成显示 很多软件中(比如QQ)用到了许多圆形图片,作为用户头像等等,原始图片往往是方形的,那么怎么样将方形的图片显示成圆形呢? 一种方法是当背景为固定 ...

  6. Js三级联动菜单

    效果演示: <SCRIPT LANGUAGE="JavaScript"> <!-- function CreateSelect(_FormName,_SName, ...

  7. 流式计算-Jstorm提交Topology过程(上)

    Topology是Jstorm对有向无环图的抽象,内部封装了数据来源spout和数据处理单元bolt,以及spout和bolt.bolt和bolt之间的关系.它能够被提交到Jstorm集群. 本文以J ...

  8. CMDeviceMotion使用

    CMDeviceMotion使用 by 吴雪莹 manager = [[CMMotionManager alloc] init]; ViewController *__weak weakSelf=se ...

  9. LinearLayout具体解释二:LinearLayout的创建过程以及状态全程解析

    正在撰稿中,请稍等...

  10. SRM 624 Building Heights DivI 解读

    几乎相同的一标题.欲了解更多请参阅:http://community.topcoder.com/stat?c=problem_statement&pm=13211&rd=15857 思 ...