首页 > 其他 > 详细

POJ 1426 bfs

时间:2019-07-18 00:57:59      阅读:96      评论:0      收藏:0      [点我收藏+]
Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.

Input

The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.

Output

For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.

Sample Input

2
6
19
0

Sample Output

10
100100100100100100
111111111111111111

题意:找到只由0或1组成的小于100位的数能够整除题目给出的数据
技术分享图片
 1 #include<iostream>
 2 #include<queue>
 3 using namespace std;
 4 
 5 int n;
 6 void bfs(int x)
 7 {
 8 
 9     queue<long long>Q;
10     long long p=1;
11     Q.push(p);
12     while(!Q.empty())
13     {
14         p=Q.front();
15         Q.pop();
16         if(p%n==0)
17         {
18             cout<<p<<endl;
19             break;
20         }
21         Q.push(p*10);
22         Q.push(p*10+1);
23     }
24     return ;
25 }
26 
27 
28 
29 int main()
30 {
31     std::ios::sync_with_stdio(false);
32     while(cin>>n)
33     {
34         if(n==0)
35             break;
36         else
37         {
38             bfs(n);
39         }
40     }
41     return 0;
42 }
View Code

 

POJ 1426 bfs

原文:https://www.cnblogs.com/OFSHK/p/11204426.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!