Find The Multiple
来源:互联网 发布:淘宝订单自动关闭 编辑:程序博客网 时间:2024/05/18 00:33
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
26190
Sample Output
10100100100100100100111111111111111111
首先说一下题意题目要我们找一个十进制的数,划重点,输出是10进制,只是它只包含0和1的十进制数,并且这个数是给的输入的倍数。
一看便知道是深搜,我们就是在从高位到低位去找,最高位只能是1,然后不断地在后面+0(*10),+1(*10+1),就是这样的思路 ,19位就能出现所有的结果,到不了200,位,直接用long long 就可以存储
#include <iostream>#include<cstdio>#include<cstring>using namespace std;typedef unsigned long long ll;//usigned long long 是20位,long long 是19位int n;int flag;ll ans;//这个题感觉还是有点”蒙“的成分在里面,不知道为什么会这样,只是猜测会在20位的数据里面出结果void dfs(ll now,int step){ if(step>19)//超过19位,就不要再搜了,也超出了ll的数据范围 return; if(flag) return; if(now%n==0) { flag=1; ans=now; return ; } dfs(now*10,step+1); //这种添加的方式还是很简单的 if(flag) return; dfs(now*10+1,step+1); //记住这种末尾加1还是加0的方式}int main(){ while(~scanf("%d",&n)) { if(n==0) break; flag=0; dfs(1,1);//深搜不能超界 printf("%I64d\n",ans); } return 0;}
阅读全文
0 0
- POJ1426 Find The Multiple
- poj1426 Find The Multiple
- G - Find The Multiple
- poj1426 - Find The Multiple
- POJ1426 Find The Multiple
- POJ1426-Find The Multiple
- Find The Multiple
- poj find the multiple
- poj1426 Find The Multiple
- poj1426-Find The Multiple
- POJ1426 Find the multiple
- POJ1426-Find The Multiple
- POJ1426 Find The Multiple
- zoj1530 Find The Multiple
- Find The Multiple
- Find The Multiple
- poj1426 Find The Multiple
- Find The Multiple poj1426
- [bzoj4516][Sdoi2016]生成魔咒 SAM
- uva 11481 一个序列前m个中有k个不动,其他可动可不动 共有几种情况
- C# 与java的比较
- Piggy-Bank
- 面试---算法排序(2)(插入排序)
- Find The Multiple
- python学习中的一些问题
- SnailApp---数据流的控制(二)
- 火狐浏览器使用方法 安装三方插件 实现将整个网页截图成长图
- java接口特征小结
- web前端使用jQuery发送ajax请求并接受响应的代码公式
- Linux--Shell脚本
- TortoiseGit工具使用教程之二文件操作(克隆、更新、同步)
- hpuoj 【1017】985的红绿灯难题【数学】