hdu 4474 Yet Another Multiple Problem (bfs)
2014-10-24 18:53
465 查看
///给你一个数n,再给你m个k 求 各位都不为这m个数的n的最小倍数 # include<stdio.h> # include<algorithm> # include<iostream> # include<string.h> # include <string> # include<queue> using namespace std; int vis[100010],map[11],tt[11],n; int k,x; struct node { int mod; string s; } e,w; void bfs() { memset(vis,0,sizeof(vis)); queue<node>q; e.mod=0; e.s=""; q.push(e); x=0; while(!q.empty()) { e=q.front(); q.pop(); for(int i=0; i<k; i++) { w=e;/// x=w.mod*10+tt[i]; if(x==0) continue; x%=n; if(!vis[x]) { w.mod=x; w.s+=(tt[i]+'0'); vis[x]=1; if(x%n==0) { cout<< w.s <<endl; return ; } q.push(w); } } } puts("-1"); } int main() { int m,a,i,cas=0; while(~scanf("%d%d",&n,&m)) { memset(map,0,sizeof(map)); while(m--) { scanf("%d",&a); map[a]=1; } k=0; for(i=0; i<10; i++) { if(map[i]==0) tt[k++]=i; } printf("Case %d: ",++cas); bfs(); } return 0; }
相关文章推荐
- hdu 4474 Yet Another Multiple Problem 模型转换 BFS搜索 根据剩余类建图广搜
- hdu 4474 Yet Another Multiple Problem 模型转换 BFS搜索
- hdu 4474 Yet Another Multiple Problem(BFS)
- HDU 4474(Yet Another Multiple Problem)(BFS+同余定理)
- hdu 4474 Yet Another Multiple Problem ( bfs + math)
- HDU 4474 Yet Another Multiple Problem (bfs+mod运算)
- hdu 4474 Yet Another Multiple Problem bfs
- HDU 4474 Yet Another Multiple Problem(搜索 BFS)
- HDU-#4474 Yet Another Multiple Problem(BFS)
- HDU 4474 Yet Another Multiple Problem bfs枚举所有余数
- HDU 4474 Yet Another Multiple Problem【BFS+一个判断技巧】
- hdu 4474 Yet Another Multiple Problem(BFS)
- HDU 4474 Yet Another Multiple Problem(12年成都区域赛-K题-BFS)
- HDU 4474 Yet Another Multiple Problem【2012成都regional K题】 【BFS+一个判断技巧】
- HDU 4474 HDOJ Yet Another Multiple Problem 2012ACM亚洲赛成都赛区K题
- hdu 4474 Yet Another Multiple Problem
- HDU 4474 Yet Another Multiple Problem
- [bfs+余数判重+路径记录] hdu 4474 Yet Another Multiple Problem
- HDU 4474 Yet Another Multiple Problem 搜索
- HDU 4474 Yet Another Multiple Problem