POJ 1426 (BFS)
思路:用队列存储“打的表”,即从1开始,1的10倍满足条件,1的10倍+1也满足条件,判断队头是否%n==0就行。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn=200005;
const double eps=1e-8;
const double PI = acos(-1.0);
void bfs(ll n)
{
queue<ll> q;
q.push(1LL);
while(!q.empty())
{
ll t=q.front();
if(t%n==0)
{
cout<<t<<endl;
break;
}
q.pop();
q.push(t*10);
q.push(t*10+1);
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
ll n;
while(cin>>n&&n)
{
bfs(n);
}
return 0;
}