POJ 1426 Find The Multiple (BFS Foundation)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.