题目地址: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. RS100项目进展更新

    1. 添加手机界面访问网页,毕竟PDA的屏幕大小和PC机大小不一致,完成了一自适应网页,便于在手机上观看实时画面: 2. 此项目为一个远程视频监控+远程开关项目,远程PC机或者手机能操作到监控端的开关 ...

  2. 慎得慌二u赫然共和任务i个屁

    http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...

  3. 在屏幕上建立ALV

    在屏幕上创建两个文本元素空件.一个推出按钮控件.一个定制控制按钮 代码所示: *&------------------------------------------------------- ...

  4. Linux统计文件/目录数量ls -l | grep "^-" | wc -l匹配开头和结尾

    Linux统计文件数量 ls -l | grep "^-" | wc -l “^-”  一般文件 “^d” 目录文件 shell/vim中^表示开头 cat repatterns ...

  5. 将markdown格式转化为bootstrap风格html

    前言:这些年markdown格式的文件很流行,像github里project说明文档都是用markdown格式编写. 一方面,我们能够通过pandoc将markdown文件转换为html,这样将htm ...

  6. FFT算法的物理意义

    FFT是离散傅立叶变换的高速算法,能够将一个信号变换到频域.有些信号在时域上是非常难看出什么特征的,可是如果变换到频域之后,就非常easy看出特征了.这就是非常多信号分析採用FFT变换的原因.另外,F ...

  7. 八皇后问题详细分析与解答(递归法解答,c#语言描述)

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题.该问题是十九世纪著名的数学家高斯1850年提出:在8X8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或 ...

  8. 96 Stocks APIs: Bloomberg, NASDAQ and E*TRADE

      Our API directory now includes 96 stocks APIs. The newest is the Eurex VALUES API. The most popula ...

  9. anthelion编译

    编程工程 $ cd ./anthelion/anthelion/target/classes$ java -Xmx15G -cp ../Anthelion-1.0.0-jar-with-depende ...

  10. [每日一题] 11gOCP 1z0-052 :2013-09-5 runInstaller oracle of no swap

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/11186995 正确答案:A 我们先来看下面这张截图,这是我在安装Oracle 11.2.0 ...