您的位置:首页 > 其它

POJ-1426 (Find The Multiple) bfs

2018-03-04 21:10 369 查看
Find The Multiple

#include <iostream>
#include <cstdio>
#include <queue>
using namespace  std;

typedef unsigned long long ll;

struct _Node{
int depth;
ll val;
_Node(){
}
_Node(int _depth, ll _val)
{
depth = _depth; val = _val;
}
};
void bfs(int t)
{
queue<_Node> q;
q.push(_Node(0, 1));

while(!q.empty()){
_Node x = q.front(); q.pop();
//cout << x.val << endl;
if(x.depth == 19) return ;
if(x.val % t == 0)
{
printf("%I64u\n", x.val);
return ;
}

q.push(_Node(x.depth + 1, x.val * 10));
q.push(_Node(x.depth + 1, x.val * 10 + 1));
}
}
int main()
{
int t;
while(scanf("%d", &t) != EOF && t)
{
bfs(t);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: