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;
}
题解:暴搜了
#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;
}
相关文章推荐
- POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)
- POJ1426: Find The Multiple(bfs,同余定理)
- POJ1426:Find The Multiple(BFS)
- POJ1426 Find The Multiple(DFS||BFS||同余模定理)
- POJ1426 Find The Multiple —— BFS
- UVALive2701 UVA1189 POJ1426 ZOJ1530 Find The Multiple【BFS】
- POJ1426 Find The Multiple(BFS)
- (POJ1426)Find The Multiple <BFS 大数模>
- BFS POJ1426 Find The Multiple
- poj 1426 Find The Multiple(bfs)
- poj 1426 Find The Multiple(bfs)
- poj1426 - Find The Multiple [bfs 记录路径]
- poj Find The Multiple(DFS,BFS)
- POJ1426-Find The Multiple (BFS 余数)
- POJ1426 Find The Multiple(E)
- 搜索练习13/poj/problem1426 Find The Multiple/bfs
- poj 1426 Find The Multiple(搜索BFS的思想+ 同余模定理+二叉树+01哈夫曼编码)
- POJ1426-Find The Multiple
- poj Find The Multiple(DFS,BFS)
- POJ 1426-Find The Multiple(bfs)