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
26190
Sample Output
10100100100100100100111111111111111111
题意:
本题要找出数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==0) {ans=s;f=true; return ;}if(k==19) return ; //如果k超过19就不在unsigned long long的范围内了dfs(s*10,n,k+1);dfs(s*10+1,n,k+1);return ; }int main() {int n;while(cin>>n,n){ans=0;f=false;dfs(1,n,0);cout<<ans<<endl;}return 0; }
转载于:https://www.cnblogs.com/y1040511302/p/10177925.html
poj 1426 Find The Multiple (简单搜索dfs)相关推荐
- POJ 1321-棋盘问题-简单搜索DFS
POJ 1321-棋盘问题-简单搜索DFS Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编 ...
- 计蒜客-T1284 夫子云游(简单搜索dfs)
父子云游 题目链接:https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-T1284 题目描述 改编自猫腻所著的同名小说<将夜>目前 ...
- POJ 2111 Millenium Leapcow(记忆化搜索+dfs记录路径)
题目链接 思路 对N*N网格中所有点进行搜索(dfs),搜索过程中对每一步进行记忆化存储,即dp数组保存从当前点开始可获得的最高得分,若后面需要用到前面计算过的数据,直接读取dp数组即可. dp[i] ...
- 棋盘问题 简单搜索DFS
Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...
- Find The Multiple——简单搜索+大胆尝试
[题目描述] Given a positive integer n, write a program to find out a nonzero multiple m of n whose decim ...
- POJ 1426 Find The Multiple BFS
没什么好说的 从1开始进行广搜,因为只能包涵0和1,所以下一次需要搜索的值为next=now*10 和 next=now*10+1,每次判断一下就可以了,但是我一直不太明白我的代码为什么C++提交会错 ...
- POJ 1426 Find The Multiple
解题思路: 1)每5位为一个基数,枚举5位所有只包含0,1的数ans[],map[i][j]保存(ans[j]*100000^i)%n的值 2)BFS计算所有组合出现的模,直到出现0 代码 #incl ...
- POJ - 3278 Catch That Cow 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- [kuangbin带你飞]专题一 做题顺序与题解 【简单搜索】
随便说点: 博主正在刷kuangbin专题的题目,初学者,没接触过什么算法,刷题的初衷是备战蓝桥杯,后来发现了算法资料大多是针对acm的,挑选kuangbin专题入门也是如此,毕竟这样分类看起来比较有 ...
最新文章
- Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#Object‘的解决方法...
- 元学习Meta-Learning
- 自学linux指令分析-find
- 开始使用gradle(二)
- 扎克伯格的中文夜:想要成功就不能放弃
- utools插件开发之监听按键的命令和状态
- 【英语学习】【English L06】U05 Appointments L3 Can I cancel my reservation?
- 七种武器——.NET工程师求职面试必杀技(转)
- layui table 表格两种赋值方式下,data分页效果有效, url分页效果的失效 问题的解决。
- lua和torch的安装
- 深入理解分布式之抉择分布式锁
- 【EasyPR】Linux安装使用EasyPR开源车牌识别系统
- 计算机软件购销合同模版,软件销售合同范本
- 408代码题暴力破解——混分归纳总结
- 基于Spring Boot旅游打卡小程序系统的设计与实现【Java毕业设计·安装调试·代码讲解·文档报告】
- Oracle SQL基础
- 用python画好看的图片,几张好看的HTML图片和利用Python画的好看的图
- adobe framemaker 资料
- 【实战教程】使用知晓云完成微信卡券消息的处理
- 高质量项目管理-甘特图模板+教程(附下载包)/ PMP项目管理可用
热门文章
- 保留五天的日志 php,怎样让日志在归档目录保留5天?
- Vue3.0 + Ts 项目使用element-plus 自动按需导入 使用v-loading报错
- vue组件内数值做watch监听,首次监听不到的问题
- js时间格式化 YYYY/MM/DD HH:MM:SSS
- 最简单的基于DirectShow的示例:视频播放器自定义版
- 前后端分离 获取用户ip_前后端分离应用——用户信息传递
- 判断文件是否损坏_Bash技巧:把变量赋值为换行符,判断文件是否以换行符结尾...
- asp.net 下拉框绑定值
- 计算机基础知识必刷,《2019年江苏专转本考试-计算机基础必刷题题库(第四章)》...
- 【2020模拟考试T2】【PAT乙】1032 挖掘机技术哪家强 (20分) 模拟,STL