Find The Multiple POJ 1426

题目链接: http://poj.org/problem?id=1426

题意:给你一个数, 找出是这个数的倍数的一个数,且找出的这个数只能由1和0构成。(题中输出示例给的是满足条件的其中一个数,比较大,我们只需找出满足条件的最小的数即可。)

////C++交TLE , G++ 交 AC代码

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
using namespace std;
typedef long long LL;

LL BFS(LL n)
{
    queue<LL>Q;
    Q.push(1);

    while(Q.size())
    {
       LL p = Q.front();
       Q.pop();

        if(p % n ==0)
            return p;

        Q.push(p*10);
        Q.push(p*10+1);
    }
    return -1;
}
int main()
{
    LL n;

    while(scanf("%lld", &n), n!=0)
    {
        LL ans = BFS(n);
        printf("%lld
", ans);
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/daydayupacm/p/5680452.html