hdu1226 :点击打开题目链接

本题目由于题目意思,容易得知是一道广搜的题目。

首先。 我们需要知道 ,大数取模,比如 如何判断1234567 对15 取模的数为多少?答案是7,但是如果他是大数怎么办,

假设num数组存一个大数;左边为高位,右边为低位

int temp=0;

for(int i=最高位;i<=个位;i++)

temp=(temp * 某进制+num[i])%N;

return temp;   //  最终的temp就是bignumber  mod N 的值。

如果该余数出现过就没必要再次进队列了,因为此次模一样代表着下次的模也一样当这个数的模为0,那么前面的数模早已经为0,所以,后者没必要进队列。

.12

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<queue> using namespace std;
const int INF=~(1<<31);
const int MM=1005; int N,C,M;
bool digit[18],vis[5005]; int mod(string& a)
{
int temp=0;
for(int i=0; i<a.size(); i++)
{
temp=(temp*C+(int)a[i])%N;
}
return temp;
}
void print(string& a)
{
for(int i=0; i<a.size(); i++)
{
printf("%X",(int)a[i]);
}
cout<<endl;
}
bool bfs()
{
queue<string>q;
string a,b;
for(int i=1; i<=15; i++)
{
if(digit[i])
{
a=(char)i;
if(mod(a)==0)
{
print(a);
return false;
}
q.push(a);
}
}
while(!q.empty())
{
a=q.front();
q.pop();
for(int i=0; i<=15; i++)
{
if(digit[i]&&a.size()+1<=500)
{
b=a+(char)i;
int mood=mod(b);
if(mood==0)
{
print(b);
return false;
}
else
{
if(vis[mood]==0)
{
vis[mood]=1;
q.push(b);
}
}
}
}
}
return true;
}
int main(void)
{
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
memset(digit,0,sizeof(digit));
memset(vis,0,sizeof(vis));
scanf("%d%d%d",&N,&C,&M);
for(int i=0; i<M; i++)
{
int val;
scanf("%x",&val);
digit[val]=true;
}
if(N==0)
{
if(digit[0]) cout<<"0"<<endl;
else cout<<"give me the bomb please"<<endl;
continue;
}
if(bfs()) cout<<"give me the bomb please"<<endl;
}
return 0;
}

hdu1226的更多相关文章

  1. 超级密码 hdu1226 bfs

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

  2. HDU-1226 超级密码 (BFS+剪枝)

    Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息:密 码是一个C进 ...

  3. hdu1226 超级密码 (BFS,里面用了大数取余原理)

    Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息: 密码是一个C进 ...

  4. HDU1226:超级密码(BFS)

    Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息: 密码是一个C进 ...

  5. hdu1226超级密码 bfs

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

  6. hdu 1226 BFS + bfs记录路径

    http://acm.hdu.edu.cn/showproblem.php? pid=1226 为了节省空间.您可以使用vis初始化数组初始化-1. 发现BFSeasy错了地方 始一直WA在这里:就是 ...

  7. 2019的hdu暑假作业(欢迎纠错)

    1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ me ...

随机推荐

  1. HDU 5667 Sequence【矩阵快速幂+费马小定理】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5667 题意: Lcomyn 是个很厉害的选手,除了喜欢写17kb+的代码题,偶尔还会写数学题.他找到 ...

  2. noip2013货车运输

    P1967 货车运输 题目描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过 ...

  3. 深究Spring中Bean的生命周期

    前言 这其实是一道面试题,是我在面试百度的时候被问到的,当时没有答出来(因为自己真的很菜),后来在网上寻找答案,看到也是一头雾水,直到看到了<Spring in action>这本书,书上 ...

  4. Maven打包时过滤测试代码或指定特定的测试类(maven-surefire-plugin)

    1.过滤整个测试代码,可以直接在命令行上指定 mvn clean install -Dmaven.test.skip=true 提示:以上为举例,具体的构建阶段可以自定义,其中maven.test.s ...

  5. 【kotlin】报错 Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type List<String>?

    报错如下: 解决如下: 另一种情况: 解决如下:

  6. ASP.NETCore使用AutoFac依赖注入

    原文:ASP.NETCore使用AutoFac依赖注入 实现代码 1.新建接口类:IRepository.cs,规范各个操作类的都有那些方法,方便管理. using System; using Sys ...

  7. atitit. hb 原生sql跨数据库解决原理 获得hb 数据库类型执行期获得Dialect

    atitit. hb 原生sql跨数据库解决原理 获得hb 数据库类型执行期获得Dialect   #-----原理 Hibernate 执行期获得Dialect   2010-07-28 12:59 ...

  8. MAC上Nuclide的安装

    MAC上Nuclide的安装 本文版权归作者全部,如需转载请联系孟祥月 CSDN博客:http://blog.csdn.net/mengxiangyue 独立博客:http://mengxiangyu ...

  9. crm操作约会实体

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Crm.Sdk.Messages;     using Microsoft ...

  10. Chrome浏览器 js 关闭窗口失效解决方法

    //获取元素ID var DelHtml = document.getElementById("imgdel"); //alert(DelHtml); //添加点击事件 DelHt ...