HDU 1226 超级密码 (搜素)
题目地址: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 超级密码 (搜素)的更多相关文章
- HDU 1226 超级密码(数学 bfs)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1226 超级密码 Time Limit: 20000/10000 MS (Java/Others) ...
- hdu.1226.超级密码(bfs)
超级密码 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- hdu 1226 超级密码
超级密码 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem D ...
- hdu 1226 超级密码(bfs+余数判重)
题意:略过 分析:用m个数字组成一个能够被n整除的c进制数的最小值,实际上本题的关键就在于这个最小值上. 首先确定我们的思路是从小到大寻找.先查看一位数,即查看着m个数字是否能被n整除:若不能,就查 ...
- HDU 1226 超级密码(BFS) (还需研究)
Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Desc ...
- HDOJ 1226 超级密码
超级密码 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDOJ 1226 超级密码(bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1226 思路分析:题目要求寻找一串长度不大于500的C进制的密码,且该密码需要为十进制数N的整数倍. & ...
- HDU 1226 超级password
跟POJ 1465 multiple 类是.仅仅只是多了2个条件,长度不能超过500.还有就是 可能不是十进制. bfs+同余定理,就是用 mod 来判重. G++ 15ms 每次枚举一位,然后记录下 ...
- hdu1226超级密码 bfs
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1226/ 题目大意是:寻找一个五百位之内的C进制密码,该密码是N的正整数倍,而且只能用给定的数构成密码,求这样的密 ...
随机推荐
- Jenkins快速搭建持续集成
基于Jenkins快速搭建持续集成环境 Jenkins+tortoisesvn+MSBuild做到持续集成 附Jenkins的使用:http://www.infoq.com/cn/articles/M ...
- 11586 - Train Tracks
Problem J: Train Tracks Andy loves his set of wooden trains and railroad tracks. Each day, Daddy has ...
- ORA-00942:表或视图不存在(低级错误)
在好多时候.调试PL/SQL对象时会报.ORA-00942 看看错误原因吧: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamFjc29uX2JhaQ== ...
- 【 .NET 面向对象程序设计进阶》】【 《.NET 面向对象编程基础》】【《正则表达式助手》】
<.NET 面向对象程序设计进阶> <.NET 面向对象程序设计进阶> <正则表达式助手>
- 通过程序预览Office文档
我承认,标题是夸大了,就是为了吸引注意力.这里只有Word文档和Excel文档的预览代码. Word://此部分来源:http://princed.mblogger.cn/posts/11885.as ...
- Qt Style Sheets Examples(QT真是有很全的文档)
http://doc.qt.io/qt-5/stylesheet-examples.html http://doc.qt.io/qt-4.8/stylesheet.html
- 基于visual Studio2013解决面试题之0208二叉搜索树后序遍历序列
题目
- css怎样使顶端悬浮导航栏不遮住下面一层页面内容
在两个层之间加这个<span class="blank" style="height:20px;"></span>,其中高度可以自己设置 ...
- Ubuntu12.04创建 Eclipse launcher
Ubuntu 12.04 默认无法launcher Eclipse快捷图标到左侧Dash,需要手工配置,步骤如下: 1) 首先,创建并打开 ~/.local/share/applications/op ...
- crontab linux
第1列分钟1-59第2列小时1-23(0表示子夜)第3列日1-31第4列月1-12第5列星期0-6(0表示星期天)第6列要运行的命令 下面是crontab的格式:分 时 日 月 星期 要运行的命令 这 ...