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 ...
随机推荐
- ClickHouse(14)ClickHouse合并树MergeTree家族表引擎之VersionedCollapsingMergeTree详细解析
目录 建表语法 使用场景 合并算法 使用例子. 资料分享 参考文章 VersionedCollapsingMergeTree引擎继承自MergeTree并将折叠行的逻辑添加到合并数据部分的算法中.Ve ...
- Python 潮流周刊第 19 期摘要
原文全文:https://pythoncat.top/posts/2023-09-09-weekly 文章&教程 1.Mojo 终于提供下载了! 2.我们能从 PEP-703 中学到什么? 3 ...
- 4.基于Label studio的训练数据标注指南:情感分析任务观点词抽取、属性抽取
情感分析任务Label Studio使用指南 1.基于Label studio的训练数据标注指南:信息抽取(实体关系抽取).文本分类等 2.基于Label studio的训练数据标注指南:(智能文档) ...
- 8.2 Windows驱动开发:内核解锁与强删文件
在某些时候我们的系统中会出现一些无法被正常删除的文件,如果想要强制删除则需要在驱动层面对其进行解锁后才可删掉,而所谓的解锁其实就是释放掉文件描述符(句柄表)占用,文件解锁的核心原理是通过调用ObSet ...
- AI自动生成视频保姆级教程,还能赚包辣条哦~
友友们,小卷今天给大家分享下如何通过AI自动生成视频,只需要3分钟就能做出一个视频,把视频发到B站.抖音.西瓜上,还能赚包辣条哦~ 文末给大家准备了AI变现的案例及AIGC知识库,记得领取哦! 1.收 ...
- 限流设置之Nginx篇
question1:为什么用到Nginx,Nginx有什么功能? 1.反向代理(建议先看正向代理,反向代理则是同样你要与对方服务器建立连接,但是,代理服务器和目标服务器在一个LAN下,所以我们需要与代 ...
- Kubernetes全栈架构师(Docker基础)--学习笔记
目录 Docker基础入门 Docker基本命令 Dockerfile用法 制作小镜像上 多阶段制作小镜像下 Scratch空镜像 Docker基础入门 Docker:它是一个开源的软件项目,在Lin ...
- CF-926(已更新:B)
CF-926 两点睡,七点起,阎王夸我好身体-- 主要这场实在是难绷,两个小时都在C题上吊死了,也不是没想过跳题,只是后面的题我更是一点思路都没有-^- "就喜欢这种被揭穿的感觉,爽!&qu ...
- NC51097 Parity game
题目链接 题目 题目描述 Now and then you play the following game with your friend. Your friend writes down a se ...
- 使用V2R做反向代理内网穿透
环境 内网服务器Prob1位于内网LAN1, 内网服务器Prob2位于内网LAN2, 外网服务器Serv1位于IP 123.123.123.123 内网节点配置 内网节点没有inbound,只需要配置 ...