POJ-1426 Find The Multiple
程序员文章站
2022-06-12 09:15:09
...
POJ-1426 Find The Multiple
题目链接:POJ-1426
题目大意:找到一个数 这个数只由1或0组成 且是给定数的整倍数
解题思路:只由1或者0组成 那么就从1为起点 每次乘10 或者乘10+1 就能覆盖到所有的数 BFS搜索即可 注意示例给定的不是最小解 不要被误导
代码块:
#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;
ll n;
ll res = 1;
void bfs(ll x);
int main(){
while(cin>>n){
if(n == 0)return 0;
if(n != 1)bfs(n);
cout<<res<<endl;
res = 1;
}
return 0;
}
void bfs(ll x){
queue<ll> queueA;
queueA.push(1);
while(queueA.size()){
ll nowValue = queueA.front();
if(nowValue % x == 0){
res = nowValue;
return;
}
else{
queueA.push(nowValue * 10);
queueA.push(nowValue * 10 + 1);
}
queueA.pop();
}
}
推荐阅读
-
OPPO Find X3再升级:支持1Hz-120Hz动态帧率 功耗降低50%
-
编译php报错:/usr/bin/ld: cannot find -liconv解决办法
-
Bundler could not find compatible versions for gem “bundler”: In Gemfile:
-
cocoapods ould not find 'cocoapods' (>= 0) among 200 total gem(s) (Gem::LoadError)
-
could not find cudnnCreate in cudnn DSO
-
【Redis】ERROR: Could not find a valid gem 'redis-3.0.0' (>= 0) in any repository
-
Could not find ‘ffi‘ (>= 1.3.0) among 86 total gem(s) (Gem::MissingSpecError)
-
ERROR: virtualenvwrapper could not find virtualenv in your path
-
ERROR: virtualenvwrapper could not find virtualenv in your path
-
ERROR: Could not find a valid gem 'redis' (>= 0) in any repository