• POJ1426Find The Multiplebfs


    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
  • 相关阅读:
    【Project Euler】1 第一题
    【OpenCV归纳】5 图像处理
    【OpenCV归纳】4 关于HighGUI
    【OpenCV归纳】3 在实例中学习简单函数以及数据读写
    【OpenCV归纳】2 读写视频
    【OpenCV归纳】1 体验OpenCV
    【SICP练习】27 练习1.33
    【SICP练习】26 练习1.32
    【SICP练习】25 练习1.31
    【SICP练习】24 练习1.30
  • 原文地址:https://www.cnblogs.com/OFSHK/p/11204426.html
Copyright © 2020-2023  润新知