题目链接:

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. Objective-C异步编程

    1. 不要阻塞主线程 不管在进行iOS还是OS X开发中,主线程都只应该处理用户交互和界面布局,好的程序通常能够随时快速响应用户的操作,所以CPU密集型或者会阻塞线程的代码应该在其他位置去执行,我指的 ...

  2. bzoj 3218 a + b Problem(最小割+主席树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3218 [题意] 给n个格子涂白或黑色,白则wi,黑则bi的好看度,若黑格i存在: 1& ...

  3. DRAM 内存介绍(一)

    转载自博客大神迈克老狼的blog: http://www.cnblogs.com/mikewolf2002/archive/2012/11/13/2768804.html 参考资料:http://ww ...

  4. 《Genesis-3D开源游戏引擎完整实例教程-跑酷游戏篇:简介及目录》(附上完整工程文件)

    跑酷游戏制作 游戏类型: 此游戏Demo,为跑酷类游戏. 框架简介: 游戏通常由程序代码和资源组成.如果说模型.贴图.声音之类的可以给游戏环境提供一个物理描述和设置,那么脚本和代码块会给游戏赋予生命, ...

  5. [置顶] Kendo UI开发教程: Kendo UI 示例及总结

    前面基本介绍完Kendo UI开发的基本概念和开发步骤,Kendo UI的示例网站为http://demos.kendoui.com/ ,包含了三个部分 Web DemoMobile DemoData ...

  6. 【转】Maven实战(九)---模块聚合和继承

    原博文出自于:http://blog.csdn.net/liutengteng130/article/details/47001831   感谢! 类之间有聚合和继承关系,Maven也具备这样的设计原 ...

  7. build.gradle 使用tips

    7.查看依赖 gradlew [你想查看的module]:dependencies >dependencies.txt 6.buildToolsVersion build tools版本号 co ...

  8. hive UDTF函数

    之前说过HIVE,UDF(User-Defined-Function)函数的编写和使用,现在来看看UDTF的编写和使用. 1. UDTF介绍 UDTF(User-Defined Table-Gener ...

  9. BestCoder Round #68 (div.2) geometry(hdu 5605)

    geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  10. [C语言 - 4] 指针

    存放变量地址的变量 int a = 1; int *p; p = &a;   在64位系统中,占用8个字节 直接引用 间接引用 *p : 指针指向的变量的值 不要使用未初始化的指针     1 ...