题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1226

题目意思:

给一个N,给nn个jj进制的数字,问最小的不超过500位的由这些数字组成的jj进制数是十进制数N的正整数倍。

解题思路:

BFS。

因为N<=5000,所以用余数判重。

代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#define eps 1e-6
#define INF 0x1f1f1f1f
#define PI acos(-1.0)
#define ll __int64
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; /*
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
*/ bool vis[5500];
char save[20];
int n,jj,nn; struct Inf
{
string s;
int m,len;
}; bool cmp(char a,char b)
{
return int(a)<int(b);
} void bfs()
{
memset(vis,false,sizeof(vis));
queue<Inf>myq; for(int i=1;i<=nn;i++)
{
if(save[i]=='0')
continue;
Inf tmp;
tmp.s="",tmp.len=1;
tmp.s+=save[i];
tmp.m=((save[i]>='0'&&save[i]<='9')?(save[i]-'0'):(10+save[i]-'A'))%n;
if(tmp.m==0) //只有一位的情况 特殊处理
{
cout<<tmp.s<<endl;
return ;
}
vis[tmp.m]=true;
myq.push(tmp);
} while(!myq.empty())
{
Inf tt=myq.front();
myq.pop();
for(int i=1;i<=nn;i++)
{
int aa=(save[i]>='0'&&save[i]<='9')?(save[i]-'0'):(10+save[i]-'A');
int t=(tt.m*jj+aa)%n; if(!t) //不小于2位的情况
{
cout<<tt.s;
printf("%c\n",save[i]);
return ;
}
if(vis[t])
continue;
vis[t]=true;
Inf cur;
cur.len=tt.len+1;
if(cur.len>=500) //超过500位
continue;
cur.s=tt.s+save[i];
cur.m=t;
myq.push(cur);
}
}
printf("give me the bomb please\n");
return ; } int main()
{
int t; scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&jj,&nn);
getchar();
//fflush(stdin); //由于这句话 ,wa了一上午
for(int i=1;i<=nn;i++)
scanf("%s",save+i);
//save[nn+1]='\0';
sort(save+1,save+nn+1,cmp);
if(n==0)
{
if(save[1]=='0')
printf("0\n");
else
printf("give me the bomb please\n");
continue;
}
//printf("%s\n",save+1);
bfs();
} return 0;
}

BFS-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. HDU 1226 超级密码 (搜素)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1226 题意简单,本来是一道很简单的搜素题目. 但是有两个bug: 1.M个整数可能有重复的. 2.N可 ...

  7. HDOJ 1226 超级密码

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

  8. HDOJ 1226 超级密码(bfs)

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

  9. HDU 1226 超级password

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

  10. hdu1226超级密码 bfs

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

随机推荐

  1. 你今天Python了吗?(下)

    在体验了wxPython的强大之后,让我们把注意力集中到Twisted上来.在C++的世界里,你会发现一个很棒的网络应用框架,那就是ACE了:在Python的地盘,Twisted则是在网络应用框架中当 ...

  2. Tkinter教程之Text(2)篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811347 '''Tkinter教程之Text(2)篇''''''6.使用tag来指定文本的属 ...

  3. Static块详解

    首先,我们先看一段程序,代码如下: public class Father { public Father() //构造方法 { System.out.println(" 父类构造方法&qu ...

  4. the application could not be verified

    在iphone上安装app时,提示the application could not be verified 解决方式: 将iphone已有的这个app卸载,然后安装就可以了.

  5. nova --debug image-list

    nova --debug image-list DEBUG (session:) REQ: curl -g -i -X GET http://liberty-aio:35357/v3 -H " ...

  6. work5

    这一次写的内容是黄金豆小游戏,由于现在偏重写服务器端.对于算法层面其实涉及不多,更多偏于工程上的架构. 总而言之本次作业的服务器核心是用web.py所写,而且为了方便其他用户写客户端,架构非常简单. ...

  7. HDU 5833 Zhu and 772002 (高斯消元)

    Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...

  8. HDU 5826 physics (积分推导)

    physics 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5826 Description There are n balls on a smoo ...

  9. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  10. 三星手机 Samsung Galaxy S3 无法复制粘贴的不完美解决方法

    问题简单描述 从上周开始我的Samsung Galaxy S3手机就无法实现复制粘贴功能了,每次复制时都提示复制到了剪贴板,但是粘贴时就会发现根本粘贴不了,无法打开剪贴板.真的是莫明其妙啊,我的手机没 ...