POJ-1426 题解
Find The Multiple
题目大意
输入一个正整数n(不超过200)
求一个m满足:
- m是n的倍数
- m只由0和1构成(不是二进制)
- m不超过100位
Time: 1000 ms
Memory: 10000 kB
解题思路及分析
搜索bfs
搜索树的每个节点的两个子节点即为父节点后面加一位0和1
题干说m不超过100位对这道题貌似没用,用longlong就可以
题目为special judge 结果与样例不同
AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long llong;
llong n;
llong bfs()
{
queue<llong> q;
q.push(1);
while (!q.empty())
{
llong x = q.front();
q.pop();
if (x % n == 0)
{
return x;
}
x *= 10;
for (int i = 0; i < 2; i++)
{
llong xx = x + i;
q.push(xx);
}
}
return 0;
}
int main()
{
while (~scanf("%lld", &n) && n)
{
printf("%lld\n", bfs());
}
return 0;
}