标签:style blog color os 2014 io
题意为求出只由0,1组成的并且是所给数倍数的数,
广搜。。
因为首位不能为0,因此必为1;所以搜索的下一层为上一层的10倍和10倍加1;
#include<stdio.h>
#include<string.h>
#include<iostream>
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 1426 Find The Multiple,布布扣,bubuko.com
标签:style blog color os 2014 io
原文地址:http://blog.csdn.net/asuxiexie/article/details/37728777