POJ 1426(BFS)

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <queue>
 7 using namespace std;
 8 int n;
 9 void bfs()
10 {
11     queue<long long>q;
12     q.push(1);
13     while(!q.empty())
14     {
15         long long sum=q.front();q.pop();
16         if(sum%n==0)
17         {
18             printf("%I64d\n",sum);
19             return;
20         }
21         q.push(sum*10);
22         q.push(sum*10+1);
23     }
24 }
25 int main(int argc, char *argv[])
26 {
27     
28     while(scanf("%d",&n)!=EOF)
29     {
30         if(n==0)
31         break;
32         bfs();
33     }
34     return 0;
35 }

猜你喜欢

转载自www.cnblogs.com/huluxin/p/9363599.html