POJ_1426 Find The Multiple(dfs)

题目来源:http://poj.org/problem?id=1426


题目大意:给出一个数n,它不会超过200,求他的一个倍数,此倍数要求由1和0组成,且不超过200位。

//满足上述条件的倍数肯定有很多个,只要输出其中一个即可


这个题啊,算了,直接上代码了==

/****************
*****深搜********
*****************/
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>

using namespace std;
bool found;//标志有没有找到

void dfs( unsigned __int64 ans, int n, int cnt)
{
    if( found)//如果找到了的话,直接返回
        return;

    if( ans % n == 0)//如果ans可以整除n
    {
        printf("%I64u\n",ans);
        found = true;//找到了
    }

    if( cnt == 19)
        return;//cnt大于19的话,超出范围 回溯

    dfs( ans*10, n, cnt+1);
    dfs( ans*10+1, n, cnt+1);
}

int main()
{
    int n;
    while( ~scanf("%d",&n) && n)
    {
        found = false;
        dfs(1,n,0);//从1开始搜索,ans记录搜索的次数
    }


    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值