Find The Multiple 题解
The long-lost Sunday is coming again, and the ACM Laboratory Elimination Competition of Beihua University has begun. Now you have to complete a task: XLS is very happy, because IG won. Now to make him happy, just ask you to help him solve this problem, give you an n, let you find a multiple of M and m for n, but M has a limit. His number is only 0 or 1\. Can you help him solve this problem?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
Each input you export a corresponding M, m does not know the unique number of m does not exceed 200 bits.Sample Input
100
2Sample Output
100
10
题意理解:
老实说,我刚开始看了很久都没看懂==。其实题目的意思呐就是在1和0组成的数里面找n的倍数,这样是不是清晰多了,害
DFS搜索法:
#include<stdio.h>
#include<iostream>
#include<queue>
#include<math.h>
using namespace std; long long n,now,cnt; long long bfs(long long n)
{
queue<long long> q;
q.push(1);
while(q.size())
{
now=q.front();
q.pop();
cnt=(long long)log10(now)+1;
// printf("yi--%lld %lld\n",cnt,now);
if(cnt>200) break;
if(now%n==0) return now;
q.push(now*10);
q.push(now*10+1);//若有其一除得尽,则return ;
}
return 0;
} int main()
{
while(cin>>n && n)
{
cnt=0;
cout<<bfs(n)<<endl;
}
return 0;
}
Find The Multiple 题解的更多相关文章
- [POJ2356]Find a multiple 题解(鸽巢原理)
[POJ2356]Find a multiple Description -The input contains N natural (i.e. positive integer) numbers ( ...
- Problems to be upsolved
Donation 官方题解尚未看懂. comet oj contest15 双11特惠hard Mobitel Small Multiple 题解 为什么可以如此缩点? Candy Retributi ...
- 题解报告:poj 1426 Find The Multiple(bfs、dfs)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- HDU 1019 Least Common Multiple 数学题解
求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...
- 题解 AT4164 【[ABC102A] Multiple of 2 and N】
首先我们先来回忆一下小学一年级就学过的知识:任何一个偶数都是 \(2\) 的倍数,那么我们就可以分成两种情况考虑:奇数和偶数. 对于偶数,我们可以直接将其输出,因为它必定能被 \(2\) 与它自己整除 ...
- Lowest Common Multiple Plus 题解
求n个数的最小公倍数. Input输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行.你可以假设最后的 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- LeetCode Read N Characters Given Read4 II - Call multiple times
原题链接在这里:https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/ 题目: The ...
- NBUT1541 Rainwater 题解
http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1541 When rain, nocLyt discovered a magical phenomeno ...
- Find The Multiple 分类: 搜索 POJ 2015-08-09 15:19 3人阅读 评论(0) 收藏
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21851 Accepted: 8984 Sp ...
随机推荐
- Fabric网络升级(三)
原文来自这里. 如果不熟悉capability,那么操作前可以查阅Capabilities.需要注意的是在启用capabilities前,需要升级归属该通道的peer节点和排序节点. 更多关于最新版F ...
- c和c++编译器之gcc和mingw
三大编译器:gcc,llvm,clang 什么是gcc? gcc 官方网站:https://gcc.gnu.org GCC(GNU Compiler Collection,GNU编译器套件),是由 G ...
- 从零开始配置vim(20)——模糊查询
在讲解vim的基础功能的时候,介绍过了vim的各种查询技巧,在同一个文件中进行搜索的话,那些技巧很有用.在多个文件中我们介绍了使用vim自带的 :grep命令进行搜索,使用quickfix 列表进行跳 ...
- TienChin-课程管理-数据表创建
CREATE TABLE `tienchin_course` ( `course_id` int NOT NULL AUTO_INCREMENT COMMENT '课程ID', `type` int ...
- 【SpringBoot】当AOP引发的异常与@RestControllerAdvice擦肩而过:异常处理的盲点揭秘
各位上午/下午/晚上好呀! 今天在写bug的时候发现一个这样的问题: AOP抛出的异常竟然没有被@RestControllerAdvice注解修饰的异常统一处理类处理. 有一个需求,对某些加了自定义注 ...
- 突破性的多语言代码大模型基CodeShell:引领AI编程新时代
突破性的多语言代码大模型基CodeShell:北京大学与四川天府银行联合打造,引领AI编程新时代 1.CodeShell简介 CodeShell是北京大学知识计算实验室联合四川天府银行AI团队研发的多 ...
- 基于Ernie-3.0 CAIL2019法研杯要素识别多标签分类任务
相关项目: Paddlenlp之UIE模型实战实体抽取任务[打车数据.快递单] Paddlenlp之UIE分类模型[以情感倾向分析新闻分类为例]含智能标注方案) 应用实践:分类模型大集成者[Paddl ...
- NLP涉及技术原理和应用简单讲解【一】:paddle(梯度裁剪、ONNX协议、动态图转静态图、推理部署)
参考链接: https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/advanced/gradient_clip_cn.html 1. ...
- 5.2 Windows驱动开发:内核取KERNEL模块基址
模块是程序加载时被动态装载的,模块在装载后其存在于内存中同样存在一个内存基址,当我们需要操作这个模块时,通常第一步就是要得到该模块的内存基址,模块分为用户模块和内核模块,这里的用户模块指的是应用层进程 ...
- 8.1 C++ STL 变易拷贝算法
C++ STL中的变易算法(Modifying Algorithms)是指那些能够修改容器内容的算法,主要用于修改容器中的数据,例如插入.删除.替换等操作.这些算法同样定义在头文件 <algor ...