版权声明:本文为博主原创文章,转载请注明出处( • ̀ω•́ )✧ https://blog.csdn.net/wangws_sb/article/details/83108055
题意: 给出一个整数n,(1 <= n <= 200)。求出任意一个它的倍数m,要求m必须只由十进制的’0’或’1’组成。m第一个数字必须是1,且n不大于200,m不超过100个十进制数字。
题解:BFS,M从1开始遍历所有可能的值。不知道为什么long long就可以(╥╯^╰╥)
AC代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
using namespace std;
int n,m;
queue <long long> q;
void bfs()
{
q.push(1);
while(!q.empty())
{
long long t=q.front();
q.pop();
if(t%n==0)
{
cout<<t<<endl;
return ;
}
q.push(t*10);
q.push(t*10+1);
}
return ;
}
int main()
{
while(cin>>n&&n)
{
while(!q.empty())
{
q.pop();
}
bfs();
}
return 0;
}