HDU 1226 超级密码(BFS)
来源:互联网 发布:dnf趣味数据怎么查 编辑:程序博客网 时间:2024/06/06 03:32
题意:
思路:跟网络赛的一样,少了一个= ,昨晚纠结了一个晚上。。。
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>#include <queue>#include <stack>using namespace std;int n,m,k;int re[29];void init(){ scanf("%d%d%d",&n,&m,&k); char ch[3]; for(int i=0;i<k;i++) { scanf("%s",ch); if(ch[0]<='9'&&ch[0]>='0') re[i]=ch[0]-'0'; else re[i]=ch[0]-'A'+10; } sort(re,re+k);}int pre[5009];int v[5009];int ans[5009],cnt;queue<int> que;void find(int k){ if(pre[k]!=-1) find(pre[k]); ans[cnt++] = v[k];}void solve(){ if(n==0){ if(re[0]!=0) printf("give me the bomb please\n"); else printf("0\n"); return ; } memset(v,-1,sizeof(v)); while(!que.empty()) que.pop(); for(int i=0;i<k;i++) { if(re[i]){ que.push(re[i]%n); if(v[re[i]%n]==-1) pre[re[i]%n]=-1,v[re[i]%n] = re[i]; } } while(!que.empty()) { int e = que.front(); que.pop(); if(e==0) break ; for(int i=0;i<k;i++) { int t = (e*m+re[i])%n; if(v[t]!=-1) continue; pre[t] = e; v[t] = re[i]; que.push(t); } } if(v[0]==-1){ printf("give me the bomb please\n"); return ; } cnt = 0; find(0); if(cnt>500){ printf("give me the bomb please\n"); return ; } for(int i=0;i<cnt;i++){ if(ans[i]<=9) printf("%d",ans[i]); else printf("%c",ans[i]-10+'A'); }printf("\n");}int main(){ freopen("in.txt","r",stdin); int cas; scanf("%d",&cas); while(cas--) { init(); solve(); } return 0;}
- hdu 1226 超级密码bfs
- HDU 1226 超级密码(BFS)
- BFS-hdu-1226-超级密码
- hdu 1226 超级密码 bfs
- hdu 1226 超级密码【BFS】
- 【hdu】1226 超级密码【bfs】
- hdu 1226 超级密码 bfs
- Hdu-1226-超级密码 [bfs]
- [HDU 1226]超级密码:BFS
- HDU 1226超级密码(数位BFS)
- hdu 1226 超级密码 bfs+取余判重
- HDU 1226 超级密码 (bfs好题)
- HDU 1226 超级密码(BFS)
- hdu-超级密码(BFS)
- HDU 1266 超级密码 bfs
- hdu 1226 超级密码 (bfs+取余判重 poj 1465加强版 )
- hdu 1226 超级密码 BFS 挺不错的题啊!
- hdu 1226 超级密码(BFS,同余剪枝)
- SQL查询某列以B或C或D或F开始且第三个字符为"a"的数据信息
- 极客Style:12款华丽的Admin管理后台模板
- 表达式前后缀表达形式 [zz]
- Log Writer Process (LGWR)【2012-10-12】--每日一译
- 限制CListCtrl列的宽度
- HDU 1226 超级密码(BFS)
- Android中Error generating final archive: Debug certificate expired on
- 在现实增强应用Layar中显示ArcGIS数据(Ⅰ)
- 日媒:中国早没血性 不对外扩张是老传统
- vc20个使用技巧
- 关于离散小波框架变换以及多孔算法(a trous)的学习感悟
- 世界史上的6大古帝国
- HTTP URLConnection
- json与struts2进行数据交互配置详解