码迷,mamicode.com
首页 > 其他好文 > 详细

BFS/poj 1426 Find The Multiple

时间:2014-12-04 10:13:57      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   sp   on   div   log   bs   

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<queue>
 4 using namespace std;
 5 int n;
 6 bool v[210];
 7 unsigned long long bfs(int n)
 8 {
 9     memset(v,0,sizeof(v));
10     queue<unsigned long long>que;
11     unsigned long long now,next;
12 
13     now=1;v[1%n]=1;
14     que.push(now);
15 
16     while (!que.empty())
17     {
18         now=que.front();
19         if (now%n==0) break;
20         que.pop();
21 
22         next=now*10;
23         if (!v[next%n])
24         {
25             v[next%n]=1;
26             que.push(next);
27         }
28 
29         next=now*10+1;
30         if (!v[next%n])
31         {
32             v[next%n]=1;
33             que.push(next);
34         }
35 
36     }
37     return now;
38 }
39 int main()
40 {
41     scanf("%d",&n);
42     while (n!=0)
43     {
44         printf("%lld\n",bfs(n));
45         scanf("%d",&n);
46     }
47     return 0;
48 }

 

BFS/poj 1426 Find The Multiple

标签:style   blog   io   color   sp   on   div   log   bs   

原文地址:http://www.cnblogs.com/NicoleLam/p/4142020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!