E -
Find The Multiple
分析:bfs搜索,没有剪枝,若不是有题目分类,应该猜不到是搜索。。但理解一下也确实搜索是个好方法,两条分之‘0’,‘1’。
c++提交tle,g++提交ac
code:
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
typedef unsigned long long ll;
ll a,ans;
void bfs()
{
ans=1;
queue <ll> q;q.push(ans);
while(q.size())
{
ll now=q.front();
q.pop();
if( !(now%a) )
{
printf("%lld\n",now);
return ;
}
ll ne1=now*10+1,ne0=now*10;
q.push(ne1);
q.push(ne0);
}
}
int main(void)
{
while(scanf("%lld",&a)&&a)
{
bfs();
}
}