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 ...
随机推荐
- Go中字符串处理:fmt.Sprintf与string.Builder的比较
在Go语言中,我们通常会遇到两种主要的方式来处理和操作字符串:使用fmt.Sprintf函数和string.Builder类型.尽管两者都可以实现字符串的格式化和连接,但它们在性能和用法上有一些关键区 ...
- C/C++ 类与构造析构等知识
简单定义类 #include <iostream> #include <string> using namespace std; class Student { public: ...
- 遥感图像处理笔记之【FastAI Multi-label image classification】
遥感图像处理学习(4) 前言 遥感系列第4篇.遥感图像处理方向的学习者可以参考或者复刻 本文初编辑于2023年12月15日 2024年1月24日搬运至本人博客园平台 文章标题:FastAI Multi ...
- LLM面面观之RLHF平替算法DPO
1. 背景 最近本qiang~老看到一些关于大语言模型的DPO.RLHF算法,但都有些云里雾里,因此静下心来收集资料.研读论文,并执行了下开源代码,以便加深印象. 此文是本qiang~针对大语言模型的 ...
- Nginx的反向代理做负载均衡
对于一个大型网站,随着网站的访问量快速增长,单台服务器很难再支撑起需要,所以我们会购置多个服务器来满足业务量的需求,然后再利用Nginx提供的反向代理功能,来实现多台服务器间的协作功能,提高网站的处理 ...
- idea破解《当脚本破解方式无效或不方便执行时可采用此方法》
idea新版破解有时会各种不成功,很耽误事.所以,再次整理一个相对省事有效的办法.<此方式为修改idea启动脚本破解方式>内容如下: 一:下载此激活工具 二:按下图从下载的文件中找到箭头标 ...
- (python)做题记录||2024.2.4||题目是codewars的【 All Balanced Parentheses】
题目链接:https://www.codewars.com/kata/5426d7a2c2c7784365000783/python 我的解决方案: def balanced_parens(n): # ...
- 案例:推进GTID解决MySQL主主不同步问题
之前文章介绍过MySQL修改lower_case_table_names参数,如果之前大写存储的表将无法识别,需要特殊处理. 最近遇到一例应用开发人员在修改这个参数之后,为了清除之前大写存储的表,做了 ...
- Spring Boot 单元测试笔记
1. 导入JUnit5测试框架 <dependency> <groupId>org.springframework.boot</groupId> <artif ...
- NC16810 [NOIP1999]拦截导弹
题目链接 题目 题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达 ...