POJ 1426 Find The Multiple

来源:互联网 发布:淘宝信用贷款提前还款 编辑:程序博客网 时间:2024/05/29 14:25

听说可以用longlong+G++水过。。

#include<cstdio>#include<queue>using namespace std;int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        if(n==0)            break;        queue<long long>Q;        Q.push(1);        while(!Q.empty())        {            long long test=Q.front();            if(test%n==0)               {                   printf("%I64d\n",test);                   break;               }            Q.pop();            Q.push(test*10);            Q.push(test*10+1);        }    }    return 0;}

还可以dfs做,unsigned long long,由于dfs可以wa多次来二分出口,所以dfs版的ac代码时间少,内存少。。

最后,神奇的数学公式以及想法。。
膜拜大神!
详见:
優YoU http://user.qzone.qq.com/289065406/blog/1303946967
再次感谢大神!

0 0
原创粉丝点击