题目链接:

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. C# 中如何判断某个字符串是否为空的方法 分享了三个方法来判断字

    1. 三种常用的字符串判空串方法:Length法:bool isEmpty = (str.Length == 0);Empty法:bool isEmpty = (str == String.Empty ...

  2. 【C#】字符串与字符数组

    字符串与字符数组的相互转换. 字符串转换成字符数组: string ss="abcdefg"; char[] cc=ss.ToCharArray();     字符数组转换成字符串 ...

  3. Hello, Github Blog

    hello, I am using github to write a post, I am so exciting- 原文地址: http://vblog.vell001.ml/2014/03/08 ...

  4. workstack windows to openstack

    https://www.mirantis.com/openstack-portal/express-openstack-portal/migrating-from-vmware-for-windows ...

  5. POJ3237-Tree (树链剖分,线段树区间更新+点更新+区间查询)

    两个更新操作,一个将第i条路径权值改为w,一个是将a-b之间所有路径权值取反. 一个查询操作,求a-b之间路径中权值最大的边. 很容易想到维护一个最大最小值,取反就是把最大最小取反交换一下. 开始遇到 ...

  6. fx-experience-tools

    http://fxexperience.com/2012/03/announcing-fx-experience-tools/ I have some cool new stuff for you t ...

  7. Windows下cmd的替代软件——PowerCmd

    Powercmd 是一款运行在windows下的cmd增强软件(A Better Command Prompt Replacement Tool),当前最新的版本为2.2. 官方提供试用版,貌似没有功 ...

  8. UVALive 7461 Separating Pebbles (计算几何)

    Separating Pebbles 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/H Description http://7 ...

  9. [iOS基础控件 - 6.10.3] DatePicker & UIToolBar

    A.需求 1. 学习DatePicker的基本配置 2.使用TextField召唤指定类型的输入键盘View,这里使用DatePicker 3.给输入键盘上方加上一个UIToolBar,实现如关闭键盘 ...

  10. php编程冒泡排序

    <?//冒泡排序法 function bubble_sore($array) { $count = count($array); if ($count < 0) { return fals ...