POJ 1426

http://poj.org/problem?id=1426

一道广搜的题目。

题意就是给你一个n,要你求出n的倍数中,只存在0和1的那个数字

所谓的只存在0和1,那么就是某个数的十倍或者十倍+1,而那个最开始的数应该是1。

 1 Memory :5504K G++ runtime:391MS
 2 #include <iostream>
 3 #include <queue>
 4 
 5 using namespace std;
 6 
 7 int n;
 8 
 9 queue <long long >s;
10 
11 void bfs(int n)
12 {
13     while(!s.empty())
14         s.pop();
15     s.push(1);
16     while(!s.empty())
17     {
18         long long now;
19         now=s.front();
20         s.pop();
21         if(now%n==0)
22         {
23             cout<<now<<endl;
24             return ;
25         }
26         s.push(now*10);
27         s.push(now*10+1);
28     }
29 }
30 
31 int main()
32 {
33     while(cin>>n&&n)
34     {
35         bfs(n);
36     }
37     return 0;
38 }
原文地址:https://www.cnblogs.com/Tree-dream/p/5528422.html