您的位置:首页 > 其它

Poj1426 Find The Multiple (BFS)

2018-01-16 21:26 549 查看
题意:给你一个数n,让你求一个这个数的倍数,这个倍数只能由0或1组成。

题解:暴搜了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int n;
void bfs(int s){
queue<long long> q;
q.push(1);
while(!q.empty()){
long long now = q.front();
q.pop();
if(now % s == 0){
printf("%lld\n",now);
return ;
}

q.push(now*10);
q.push(now*10+1);
}
}
int main(){
while(cin >> n){
if(n == 0)
break;
bfs(n);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: