POJ 1426 Find The Multiple (深度搜素)

对比与其他的变态搜索题目来说,这道题目就系显得特别友好;

之所以贴上这道题目,是因为还能才能从这道题目中学到东西

1.找到自己想要的搜索结果之后,如何终止搜索

2.如何储存最大的数值

AC CODE:

#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
unsigned __int64 tar,ans;
bool vis;
void dfs(unsigned __int64 x,int cnt)
{
    if(vis)                    //找到了自己想要的结果,那就不断的return ;          
    {
        return ;
    }
    //printf("%I64u
",x);   //这是输出unsigned __int64 的标准格式;
    if(x%tar==0)
    {
        ans=x;
        vis=true;            //很简单,找到自己结果之后,往后的你都不想要了,那就引进一个判断变量就行
        return ;
    }
    if(cnt==19) return ;     

    dfs(x*10,cnt+1);
    dfs(x*10+1,cnt+1);
}


int main()
{
    while(cin>>tar)
    {
        if(tar==0)  break;
        ans=0;
        vis=false;
        dfs(1,0);
        cout<<ans<<endl;
    }
    return 0;
}

1.unsigned __int64 x;      对应的输出就是printf("I64u ",x);    或者就是cout<<x<<endl;

原文地址:https://www.cnblogs.com/myxdashuaige/p/8819807.html