• POJ 1426 Find The Multiple


    注:本人英语很渣,题目大意大多来自百度~=0=

     
    这个题有点坑,答案不唯一
     
    题目大意:给你一个数n, 你需要输出的是一个由1和0组成的数,此数能被n整除
     
    解题思路:用s = 1做数的起点, s*10则相当于在后面加上0, s*10+1代表在后面加1, 用long long 来保存s足够了, 每次判断一下s % n  符合条件则输出
    当然用dfs不能无限寻找下去  比如你第一次10000...0 假如n是奇数不可能有结果  所以每次递归记录一下层数;
    long long 的范围是-9223 37203 68547 75808~9223 37203 68547 75807  所以查到19层如果还找不到结果的话, 就结束递归
     
    下面是代码
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #define N 20010
    #define each(i,n) (int i=1;i<=(n);++i)
    using namespace std;
    int a;
    int dfs(long long s, int c)//c用来记录层数
    {
        if(c == 19) return 0;
        if(s % a == 0) {
            printf("%lld
    ", s);
            return 1;
        }
        else {
            int b = dfs(s * 10, c + 1);
            if(!b)
            dfs(s * 10 + 1, c + 1);
        }
    }
    int main()
    {
     while(scanf("%d", &a), a) {
            dfs(1, 0);
     }
    }
    

      

  • 相关阅读:
    guava学习--集合2&Range
    guava学习--集合1
    guava学习--FluentIterable
    guava学习--Supplier Suppliers
    guava--Joiner、Splitter、MapJoinner、MapSplitter
    python_输入一个数,判断是否是素数
    python_33_文件操作2
    python_32_文件操作1
    python_31_集合
    python_输出100:200内的素数
  • 原文地址:https://www.cnblogs.com/wangyuhao/p/4685104.html
Copyright © 2020-2023  润新知