zju/zoj 1136 Multiple(BFS)
2011-08-23 16:16
453 查看
就是不停的在后面加数。
#include<iostream> #include<cstring> #include<queue> #include<algorithm> #include<cstdio> #include<string> using namespace std; #define M 5002 bool use[M]; typedef struct li{ string path; int num; }li; int main(){ int n,m,s[M],p; li x,y; while(scanf("%d %d",&n,&m)!=EOF){ for(int i=0;i<m;i++) scanf("%d",&s[i]); if(!n){ printf("0\n"); continue; } x.path=""; x.num=0; sort(s,s+m); memset(use,false,sizeof(use)); queue<li> q; q.push(x); while(!q.empty() && !use[0] ){ x=q.front(); q.pop(); for(int j=0;j<m && !use[0];j++){ y=x; y.num=y.num*10+s[j]; if(!y.num) continue; p=y.num%n; if(use[p]) continue; y.num=p; y.path+=(s[j]+'0'); use[p]=true; q.push(y); } } cout<<(use[0]?y.path:"0")<<endl; } return 0; }
相关文章推荐
- zoj 1136 Multiple(数学+bfs)
- POJ 1465/ ZOJ 1136 : Multiple - BFS,余数判重
- ZOJ 1136 Multiple( 搜索 BFS )
- ZOJ 1136 Multiple BFS(POJ 1465)
- ZOJ 1136 Multiple BFS 取模 POJ 1465
- ZOJ 1136 Multiple(BFS)
- zoj 1530 Find The Multiple(bfs)
- 广度优先搜索,分支限界- ZOJ - 1136 Multiple
- zoj 1136 Multiple
- zoj 1136 Multiple
- UVALive2701 UVA1189 POJ1426 ZOJ1530 Find The Multiple【BFS】
- ZOJ - 1136 Multiple (同余+BFS)
- ZOJ 1136 Multiple
- zoj 1136 Multiple(bfs+数论+string)
- ZOJ 1136 / POJ 1465 Multiple
- ZOJ 1136 Multiple(分支界限算法)
- ZOJ 1136 Multiple(BFS + 数论 同余剪枝 搜索数字的倍数 )
- zoj 1136 Multiple
- ZJU2012.02月赛 F题(ZOJ 3576)
- ZOJ 1091 BFS