题目描述:输入一个数N(N<=200),求一个十进制数为其整数倍,并且这个数只由0,1,构成。
输入样例:(答案不唯一,我求的是最小的。)
2
6
19
0
输出样例:
10
1110
11001
/
/
//先写下思路:
看到题目,首先想到要用dfs,但我觉得好多人都会用dfs,所以我准备贴个队列代码题目说要由0,1,构成;所以我们可以构造由0,1组成的数再判断是否符合要求。
//
/
/
毕竟是道数论水题!!!
下面贴出我的代码,有错误帮忙指出,谢谢强大怪!
#include<cstdio>
#include<cmath>
#include<iostream>
unsigned long long a[1000001];//数组建议开大点;否则[看下面图片!!]
using namespace std;
int main()
{
unsigned long long h1,h2,t,b,n,p,q;
while(cin>>b,b){
int flag=0;
h1=1;h2=1;t=1;
a[1]=1;
while(!flag)
{
if(a[t]%b==0){flag=1;continue;}
t++;
p=10*a[h1];
q=10*a[h2]+1;
if(p<q)
{a[t]=p;h1++;}
if(p>q)
{a[t]=q;h2++;}
if(p==q)
{a[t]=p;h1++;h2++;}
}
cout<<a[t]<<endl;
}
return 0;
}
就变成了————————>
望读者别犯这种低级错误,不要像我一样!