现在的位置: 首页 > 综合 > 正文

poj 1426 Find The Multiple

2018年01月17日 ⁄ 综合 ⁄ 共 382字 ⁄ 字号 评论关闭

题意为求出只由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。。

【上篇】
【下篇】

抱歉!评论已关闭.