poj 1426 Find The Multiple (简单搜索dfs)
题目:
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
题意:
本题要找出数m,m是只有0和1构成的十进制数,并且是n的倍数,若有多个答案,输出任意一个就可以。
题解:
经过思考会发现m最大不会超过unsigned long long 的范围,所以用unsigned long long保存就可以,接下来就是深搜就ok。
代码:
#include <iostream> using namespace std;
unsigned long long ans;
bool f; void dfs(unsigned long long s,int n,int k)
{
if(f) return ;
if(s%n==) {ans=s;f=true; return ;}
if(k==) return ; //如果k超过19就不在unsigned long long的范围内了
dfs(s*,n,k+);
dfs(s*+,n,k+);
return ;
} int main()
{
int n;
while(cin>>n,n)
{
ans=;
f=false;
dfs(,n,);
cout<<ans<<endl;
}
return ;
}
poj 1426 Find The Multiple (简单搜索dfs)的更多相关文章
- POJ - 1426 Find The Multiple(搜索+数论)
转载自:優YoU http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...
- poj 1426 Find The Multiple (bfs 搜索)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18012 Accepted: 729 ...
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- DFS/BFS(同余模) POJ 1426 Find The Multiple
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...
- POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
- POJ 1426 Find The Multiple (DFS / BFS)
题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...
- POJ 2243 简单搜索 (DFS BFS A*)
题目大意:国际象棋给你一个起点和一个终点,按骑士的走法,从起点到终点的最少移动多少次. 求最少明显用bfs,下面给出三种搜索算法程序: // BFS #include<cstdio> #i ...
- 简单搜索dfs, 简单的修剪搜索
选择最合适的语言做一个项目是非常重要的.但,熟练的掌握自己的武器,这也是非常重要的. ========================================================= ...
随机推荐
- c# pda
1.去除标题栏 FormBorderStyle属性设置为none 2.去除任务栏 [System.Runtime.InteropServices.DllImport("coredll.dll ...
- css实现多行文本溢出显示省略号(…)
WebKit浏览器或移动端的页面在WebKit浏览器或移动端(绝大部分是WebKit内核的浏览器)的页面实现比较简单,可以直接使用WebKit的CSS扩展属性(WebKit是私有属性)-webkit- ...
- union的特性,去重与不去重
转载:https://blog.csdn.net/kingmax54212008/article/details/33762921 union的特性,去重与不去重 集合操作有 并,交,差 3种运算. ...
- [Linux] Vim 撤销 回退 操作
在vi中按u可以撤销一次操作 u 撤销上一步的操作 Ctrl+r 恢复上一步被撤销的操作 注意: 如果你输入“u”两次,你的文本恢复原样,那应该是你的Vim被配置在Vi兼容 ...
- NOIp2018提高组 双栈排序
这真是道神奇的题目: 原题链接 首先我们要证明以下的性质: 若原序列为\(\{a_n\}\),\(a_i\)和\(a_j\)不能同时放入一个栈中,当且仅当\(i<j,a_i<a_j\),且 ...
- POM文件分析记
pom英文全称:project object model 1.简介 pom.xml文件描述了maven项目的基本信息,比如groupId,artifactId,version等.也可以对maven项目 ...
- Day041--CSS, 盒模型, 浮动
内容回顾 表单标签 input type text 普通的文本 password 密码 radio 单选 默认选中添加checked 互斥的效果 给radio标签添加 相同的name checkbo ...
- python实现简单的百度云自动下载
最近女同让我帮助从百度云下载200个文件,给了我连接和提取码,这种重复的工作不适合人做写了一个简单的爬虫 #coding=utf-8 ''' 自动填写提取码下载百度云资源 方法: for 读取文件中的 ...
- 2018年秋季学期《c语言程序设计》编程总结
<c语言程序设计>第四周编程总结 <c语言程序设计>第五周编程总结 <c语言程序设计>第六周编程总结 <c语言程序设计>第七周编程总结 <c语言程 ...
- codeforces-1140 (div2)
A.维护一个前缀最大值,不断跳即可 #include <map> #include <set> #include <ctime> #include <cmat ...