POJ.Find The Multiple
来源:互联网 发布:什么是java系统类库 编辑:程序博客网 时间:2024/06/07 22:01
题目
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 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
大致题意
一个数N(N>0,N<200),找一个数是N的倍数,这个数是一个十进制数,它是由1,0,组成的,例如:100101010,就是一个这样的数。
思路:
很显然,这样的数不止有一个,因此,用深度优先搜索,找到了一个解即退出。用unsigned __int64
来储存其倍数x.不带符号的64位整数输出方式: printf("%I64u\n",x);
代码:
#include <iostream>#include<cstring>#include<stack>#include<cstdio>#include<algorithm>#include<cmath>#include<queue>using namespace std;bool vis;int n;void dfs( unsigned __int64 x,int n,int dep){ if(vis)return;//这两个if一定不能颠倒。 //必须先检测是否已经输出x //只有检测并没有输出过后才能放心的输出 if(x%n==0) { printf("%I64u\n",x); vis=true; return ; } //如果颠倒了之后 //如果有多个解的话会输出多个解 if(dep==19)//unsigned long long 的最大位数 return; dfs(x*10,n,dep+1); dfs(x*10+1,n,dep+1);}int main(){ while(cin>>n,n) { vis=false; dfs(1,n,0); } return 0;}
- poj find the multiple
- Find The Multiple POJ
- POJ.Find The Multiple
- Find The Multiple POJ
- Find The Multiple POJ
- Find The Multiple POJ
- Find The Multiple POJ
- Find The Multiple POJ
- Find The Multiple POJ
- POJ-Find The Multiple
- poj 1426 Find The Multiple
- Poj 1426 Find The Multiple
- POJ 1426 Find the Multiple
- poj 1426Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- 条码控件Dynamsoft Barcode Reader教程:从PDF417驾驶执照中提取数据
- 三、rabbitMQ helloWorld入门程序
- https://vuejs.org/v2/examples/svg.html
- CS20SI Tensorflow for Deeplearning课程笔记(四) word2vec with NCE loss and visualize the embeddings
- 数据类型转换
- POJ.Find The Multiple
- D
- 在CentOS7上安装RabbitMQ
- Spring Data JPA 多属性排序
- Spring集成redis实现session共享(无视服务器)
- String类的增删查改(深拷贝,现代写法)
- 01-JS特效-三大系列之offset系列
- HTML
- Java_基础—集合的遍历之迭代器遍历