设为首页 加入收藏

TOP

poj 1426 Find The Multiple
2015-07-24 05:33:26 来源: 作者: 【 】 浏览:7
Tags:poj 1426 Find The Multiple

题意为求出只由0,1组成的并且是所给数倍数的数,

广搜。。

因为首位不能为0,因此必为1;所以搜索的下一层为上一层的10倍和10倍加1;

#include
  
   
#include
   
     #include
    
      using namespace std; __int64 s[9999999]; __int64 r; void show(int q) { int i,j; s[0]=1; j=0; i=0; while(i>=j) { r=s[j]; if(r%q==0) { printf("%I64d\n",r); return ; } r=r*10; s[++i]=r; r=r+1; s[++i]=r; j++; } } int main() { int a; while(scanf("%d",&a)&&a) show(a); return 0; }
    
   
  
本题用栈的话会出现Memory Limit Exceeded。。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 3264 Balanced Lineup ST算法 下一篇C++编译与链接(2)-浅谈内部链接..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: