ZOJ 1530 - Find The Multiple
2016-01-24 22:58
274 查看
Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.
Input
The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero (0) terminates the input.
Output
For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.
Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111
[b]大致题意:[/b]
给个n,找n的十进制倍数,仅有 0 和 1 组成,找一个就行,随便哪一个。
[b]解题思路:[/b]
观察以下0,1串:
1
10 11
100 101 110 111
从n=1开始, 重复 n*10 与 n*10+1 ,由此遍历所有01串。
BFS,DFS皆可,以下采用DFS。
Input
The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero (0) terminates the input.
Output
For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.
Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111
[b]大致题意:[/b]
给个n,找n的十进制倍数,仅有 0 和 1 组成,找一个就行,随便哪一个。
[b]解题思路:[/b]
观察以下0,1串:
1
10 11
100 101 110 111
从n=1开始, 重复 n*10 与 n*10+1 ,由此遍历所有01串。
BFS,DFS皆可,以下采用DFS。
#include <iostream> #include <queue> #include <cstdio> using namespace std; queue<unsigned long long> s; int n;//输入 unsigned long long temp,p; void bfs() { while(!s.empty()) s.pop(); temp=1; s.push(temp); while(!s.empty()) { p=s.front(); s.pop(); if(p%n==0) { printf("%lld\n",p);//lld! break; } s.push(p*10); s.push(p*10+1); } } int main(){ while(scanf("%d",&n),n) { bfs(); } return 0; }
相关文章推荐
- 知乎答案怎样学caffe
- FAT32与NTFS区别
- 2015 Asia - Jakarta D - An ICPC Problem without Statement
- 3.Git远程仓库添加及克隆
- HDU-1443 Joseph
- 图像平均 均值滤波抑制噪声的原理
- django rest_framework--入门教程3
- elipse+pydev pydeliciou导入问题
- 类是如何实例化为对象的
- UISearchController VS UISearchBar and UISearchDisplayController
- 读<<人月神话>>
- zImage与uImage
- 通过shell脚本来搭建python开发环境
- 【转】cas注册后自动登录
- 基于OSGi的Virgo环境搭建(一)——环境篇
- 小白也玩数学建模--引
- 关于飞思卡尔
- PHP-文件上传到独立服务器
- 2.Git基本操作和设置
- 在CentOS 6.6 64bit上为vim 7.4安装并配置vim-airline插件