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的正整数倍,而且只能用给定的数构成密码,求这样的密 ...
随机推荐
- 技术回归01-Windows内存分配工具
很久没有写技术方面的东西了,这半年主要是在学习别人的东西,对自己提高比较大,算是一次技术回笼吧,这次学习之旅目的是结束技术方面的专注,开始向应用方面找突破口,也就是完成技术积累或者为技术的积累做坚实的 ...
- Eclipse完美汉化教程
首先我们打开http://www.eclipse.org/babel/downloads.php下载语言包. 方法一:可以复制图片里的地址通过Eclipse下载,Help→Install New So ...
- 单链表的插入删除操作(c++实现)
下列代码实现的是单链表的按序插入.链表元素的删除.链表的输出 // mylink.h 代码 #ifndef MYLINK_H #define MYLINK_H #include<iostream ...
- wifi定位原理
wifi定位和手机基站定位类别似,两者都需要收集wifi位置信息接入点. 其实WIFI奇妙,它靠的是侦測附近周围全部的无线网路基地台 (WiFi Access Point) 的 MAC Address ...
- 国际化之MessageFormat与占位符
如果一个字符串文本中包含了多个与国际化相关的数据,可以使用MessageFormat类对这些数据进行批量处理. 例如: 在2016年1月9日的时候,一场台风导致了500间房屋的摧毁和¥1000000元 ...
- CWnd中PreCreateWindow、PreSubclassWindow、SubclassWindow的区别
http://blog.csdn.net/swimmer2000/archive/2007/10/30/1856213.aspx MFC(VC6.0)的CWnd及其子类中,有如下三个函数: / ...
- 【c语言】统计一个数二进制中的1的个数
// 统计一个数二进制中的1的个数 #include <stdio.h> int count(int a) { int count = 0; while (a) { count++; a ...
- Wayland中的跨进程过程调用浅析
原文地址:http://blog.csdn.net/jinzhuojun/article/details/40264449 Wayland协议主要提供了Client端应用与Server端Composi ...
- iOS应用开发详解
<iOS应用开发详解> 基本信息 作者: 郭宏志 出版社:电子工业出版社 ISBN:9787121207075 上架时间:2013-6-28 出版日期:2013 年7月 开本:16开 ...
- iOS8指纹识别TouchID
苹果在2014年6月3日的WWDC2014开幕式上推出了新版iOS8系统,界面上iOS8与iOS7相比变化不大,只是在功能方面进行了完好.iOS8通知中心更加强大,支持消息直接回复操作,并支持Quic ...