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语言之四舍五入
在C语言中,如果进行强制类型转换,它会将所需要取的位数直接提取出来,而其他位数的数字会被直接删除,不会对提取出来的位数有任何影响 所以如果我们需要提高精度,对所取的数进行四舍五入,需要给所需去的数的最 ...
- 04-JavaScript之常见运算符
JavaScript之常见运算符 1.赋值运算符 以var x=12,y=5来演示示例 运算符 例子 等同于 运算结果 = x=y x=5 += x+=y x=x+y x=17 -= x-=y x ...
- js-模块化(三大模块化规范)
###1. JS模块化 * 模块化的理解 * 什么是模块? * 将一个复杂的程序依据一定的规则(规范)封装成几个块(文件), 并进行组合在一起 * 块的内部数据/实现是私有的, 只是向外部 ...
- Nginx 请求的11个阶段
48 1:当请求进入Nginx后先READ REQUEST HEADERS 读取头部 然后再分配由哪个指令操作 2:Identity 寻找匹配哪个Location 3:Apply Rate Limi ...
- python中socket、进程、线程、协程、池的创建方式和应用场景
进程 场景 利用多核.高计算型的程序.启动数量有限 进程是计算机中最小的资源分配单位 进程和线程是包含关系 每个进程中都至少有一条线程 可以利用多核,数据隔离 创建 销毁 切换 时间开销都比较大 随着 ...
- sql 找出不包含字母、不包含汉字的数据
--1.不包含字母 SELECT * FROM t WHERE str NOT LIKE '%[a-zA-Z]%' SELECT * FROM t --2.不包含汉字 SELECT * FROM t ...
- Java多线程处理某个线程超时的问题
ExecutorService exec = Executors.newFixedThreadPool(4); List<Future<Integer>> futures = ...
- 10.2 Vue 环境安装
Vue 环境安装 环境准备 nodejs 下载安装 https://nodejs.org/en/ 查看下载版本 C:\>node -v v7.6.0 C:\>npm -v 4.1.2 ...
- 为什么要使用50ohm阻抗?
对于接收机我们期望同轴线的损耗越低越好 对于发射机同轴线的功率效率则是越大越好 所以在二者性能最优时阻抗并不相等 https://www.sohu.com/a/109536765_335274
- Gym - 101350F Monkeying Around(线段树+树状数组)
When the monkey professor leaves his class for a short time, all the monkeys go bananas. N monkeys a ...