HDU 4474 BFS
来源:互联网 发布:mac如何更改系统语言 编辑:程序博客网 时间:2024/06/03 19:37
简单BFS + 大数取模的应用
因为n最大10000 暴搜一遍即可
#include<cstdio>#include<cstring>#include<queue>#include<stack>using namespace std;const int MAXN = 10007;struct node{int v,m,pre;void init(int tv,int tm,int tpre){v = tv, m = tm, pre = tpre;}}e[MAXN];bool exist[MAXN];bool enable[10];int main(){int n,m,id=0;while(~scanf("%d%d",&n,&m)){memset(enable,0,sizeof(enable));int i,x;for(i=0;i<m;i++){scanf("%d",&x);enable[x] = true;}printf("Case %d: ",++id);memset(exist,0,sizeof(exist));bool bans = false;int ent=0;queue<int> q;e[ent].init(0,0,-1);q.push(ent ++);while(!q.empty()){int u=q.front();q.pop();for(i=0;i<10;i++){if( !enable[i] ){if(e[u].pre == -1 && i == 0){continue;}int tm = (e[u].m * 10 + i ) % n;if(tm == 0){stack<int> answer;answer.push(i);while( e[u].pre != -1){answer.push(e[u].v);u = e[u].pre;}while(!answer.empty()){putchar('0' + answer.top());answer.pop();}puts("");bans = true;break;}if( !exist[tm] ){e[ent].init(i,tm,u);q.push(ent ++);exist[tm] = true;}}}if(bans){break;}}if(!bans){puts("-1");}}return 0;}
- HDU 4474 BFS
- hdu 4474 搜索bfs
- hdu 4474 bfs
- hdu 4474 数位BFS
- hdu 4474 BFS+思维题
- hdu 4474 数位搜索bfs
- HDU bfs
- hdu 4474 Yet Another Multiple Problem bfs
- hdu 4474 Yet Another Multiple Problem (bfs)
- hdu 4474 Yet Another Multiple Problem(BFS)
- HDU 4474(神奇的BFS+强剪枝)
- HDU 4474 Yet Another Multiple Problem BFS
- HDU 4474 同余模定理+BFS
- hdu 1175 bfs
- HDU 1072(BFS)
- HDU 1429(BFS )
- hdu 1026(BFS)
- HDU 4039 BFS
- java经典算法_034打乱数据顺序
- How to detect Safari, Chrome, IE, Firefox and Opera browser?
- opengl 画半圆弧线
- 【OpenCV入门指南】第六篇 轮廓检测 下
- 用Hough投票做物体检测(续)
- HDU 4474 BFS
- 对用户自动登录实现的代码
- 逻辑回归 广告点击率预估
- 用Hough投票做物体检测的3篇文献
- 硬件开源网站
- CListCtrl控件使用
- JDBC连接池
- 无标题
- C语言老师的一封情书