Main topic:
That is, give you a number n, find any number larger than this n, and this number is a multiple of n, and can only be composed of 0 and 1.
Problem Solving Ideas:
Just started to think about the large number of problems, but carefully think about, is worried about, because on the topic of the sample, give you these several answers are very long ... There is actually a smaller number than the answer.
Two-entry BFs, as long as the queue to enter two elements, Q.push (x*10), Q.push (x*10+1);
Code:
1# include<cstdio>2# include<iostream>3# include<queue>4 5 using namespacestd;6 7 intN;8 9 voidBFS (intx)Ten { Onequeue<Long Long>que; AQue.push (1); - while( !que.empty ()) - { the Long Longxx =Que.front (); - Que.pop (); - if(xx%x==0 ) - { +printf"%lld\n", XX); - return; + } AQue.push (Ten*xx); atQue.push (Ten*xx+1); - } - } - - intMainvoid) - { in - while(cin>>N) to { + if(n==0 ) - Break; the BFS (n); * } $ Panax Notoginseng - return 0; the}
POJ 1426 Find The Multiple (BFS Foundation)