Find The Multiple ——深搜POJ
来源:互联网 发布:疲劳检测算法 编辑:程序博客网 时间:2024/05/22 07:53
Find The Multiple
POJ - 1426Given 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.
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.
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.
26190
10100100100100100100111111111111111111
题意:找出任意一个是n的倍数且只含0和1的十进制数,这里说道n不大于200,long long int范围为19位,且long long int中只包含0和1的十进制数满足所有200之内任意一个数都有整数倍(这里需要自己想出)。
题解:开头不能为0,直接从1开始深搜,因为只能包含0和1,所以(x*10,step+1)和(x*10+1,step+1);不能超出long long范围,所以step最多是18。
代码:
#include<stdio.h>int n,flag;void dfs(long long int x,int step)//x定义为long long型{ if(flag||step>18) return ; if(x%n==0) { flag=1; printf("%lld\n",x); return ; } dfs(x*10,step+1);//满足只含0和1 dfs(x*10+1,step+1);}int main(){ while(scanf("%d",&n)&&n) { flag=0;//标记 dfs(1,0); } return 0;}
阅读全文
0 0
- Find The Multiple ——深搜POJ
- POJ 1426 ——Find The Multiple
- POJ 1426 —— Find The Multiple
- 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-1456 Find The Multiple 深搜
- poj 1426 Find The Multiple
- Poj 1426 Find The Multiple
- POJ 1426 Find the Multiple
- Floyd算法
- 双重for循环打印九九乘法表
- 过度Transition与transform 转换
- 根据后台数据动态生成表格
- zookeeper 安装的三种模式
- Find The Multiple ——深搜POJ
- 【资源】2014斯坦福机器学习视频+西瓜书pdf及答案
- node.js开发:在windows环境下安装node与环境配置
- WINFORM调用百度翻译API
- 【hihocoder 1046】K Seq(线段树)
- MySQL使用IP地址登录 ERROR 1045 (28000): Access denied for user 'root'@'11.1.81.117' (using passwor:YES)
- JSON 字符串 单引号双引号 处理
- 齐次坐标,多视图几何,三维重建数学
- [qt for android]构建项目时,出现“过程试图写入的管道不存在”错误的解决方法