Fireworks
Fireworks
POJ 1426
最近一个多月没有更新过博客了。。。虽然上个月做题的题量还不算太少,但是都没有写博客。最近这两周考试有比较多,而我又比较懒,所以一直耽搁下来了。今天可能会把一千做过的题目整理一下,多发几个博客。题目难度可能不一,因为最近做的难题不是很多。
题目来源: vjudge | POJ
分析
这个题目其实可以算是个水题了,要求输入一个数,然后算出其最小的只包含0和1的倍数。其实就是一个暴力搜索的题目,只要搜索的时候只搜索包含0,1的数的情况便可。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <cstdio> #include <algorithm> #include <iostream>
unsigned long long ans;
unsigned long long find(unsigned long long x,int n,int depth) { trueif (depth>19) truetruereturn 0;
trueif (x%n==0) true{ truetrue truetrue truetruereturn x; true}
trueunsigned long long ans1 = find(x*10,n,depth+1); trueif (ans1) truetruereturn ans1; trueunsigned long long ans2 = find(x*10+1,n,depth+1); trueif (ans2) truetruereturn ans2; truereturn 0; }
int main() { trueint n; truescanf("%d",&n); truewhile (n!=0) true{ truetruestd::cout << find(1,n,0) << std::endl;
truetruescanf("%d",&n); true} }
|