zoukankan      html  css  js  c++  java
  • POJ 1426 Find The Multiple

    题意:给出一个整数n,(1 <= n <= 200)。求出任意一个它的倍数m,要求m必须只由十进制的'0'或'1'组成。

    思路:直接深搜。网上还有DFS+同余模定理

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <sstream>
     5 #include <algorithm>
     6 #include <list>
     7 #include <map>
     8 #include <vector>
     9 #include <queue>
    10 #include <stack>
    11 #include <cmath>
    12 #include <cstdlib>
    13 //#include <memory.h>
    14 #define clc(a,b) memset(a,b,sizeof(a))
    15 using namespace std;
    16 const int maxn=100000;
    17 const int inf=0x3f3f3f3f;
    18 bool flag;
    19 void dfs(unsigned __int64 t,int n,int k){
    20     if(flag)
    21         return;
    22     if(t%n==0){
    23         printf("%I64u
    ",t);
    24         flag=true;
    25         return;
    26     }
    27     if(k==19)
    28         return;
    29     dfs(t*10,n,k+1);
    30     dfs(t*10+1,n,k+1);
    31 }
    32 int main(){
    33     int n;
    34     while(cin>>n&&n){
    35          flag=false;
    36          dfs(1,n,0);//1表示n的倍数,0表示搜索深度。应为unsigned __int64 最多19层
    37     }
    38     return 0;
    39 }
    View Code
  • 相关阅读:
    HDU 1051
    HDU 1236
    递归求gcd(a,b)
    HDU 1372
    HDU 1312
    HDU 1253
    HDU 1072
    ...别人的推荐、
    搜索总结、
    TortoiseHg简单的入门使用说明
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5366135.html
Copyright © 2011-2022 走看看