• POJ1426 Find The Multiple (宽搜思想)


    Find The Multiple
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 24768   Accepted: 10201   Special Judge

    Description

    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

    Source

     

    题意:求n个一个倍数,但这个数必须是01串

    其实就是利用宽搜的思想枚举: 第一个数是1 , 然后下一个就是 10 (1 * 10) , 11( 1 * 10 + 1),再下一个就是 100(10 * 10), 101(10 * 10 + 1),110 (11 * 10),111(11 * 10 + 1) ...然后比较坑的就是只要是n个一个倍数就行,结果不用跟这个样例一样也可以,然后用long long也能过=_=

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <queue>
     5 using namespace std;
     6 typedef long long LL;
     7 void bfs(int n)
     8 {
     9     queue<LL> q;
    10     q.push(1);
    11     while (!q.empty())
    12     {
    13         LL temp = q.front();
    14         q.pop();
    15         if (temp % n == 0)
    16         {
    17             printf("%lld
    ", temp);
    18             return;
    19         }
    20         q.push(temp * 10);
    21         q.push(temp * 10 + 1);
    22     }
    23 }
    24 int main()
    25 {
    26     int n;
    27     while (scanf("%d", &n) != EOF && n)
    28     {
    29         bfs(n);
    30     }
    31     return 0;
    32 }
    View Code

     

  • 相关阅读:
    240个jQuery插件
    MySQL的mysqldump工具导入导出数据库
    [js脚本实现]图片向上滚动并且有停顿的特效
    linux 下常用查看Apache状态语句
    小命令说明
    Linux下Tomcat的启动、关闭、杀死进程
    POJ 数学题目
    2013421 心灵感悟
    证书创建工具 (Makecert.exe)
    有的句子不长,却能鼓舞我们,成为我们坚持下去的动力
  • 原文地址:https://www.cnblogs.com/zhaopAC/p/5342760.html
Copyright © 2020-2023  润新知