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 ...
随机推荐
- 从零开始配置 vim(13)——标签页插件
原始的vim中标签页已经足够好用了.你完全可以使用原始 vim 提供的功能,但是使用插件可以让它更好看.这里我比较喜欢使用 bufferline 这个插件 安装 首先我们来安装它, 在使用 packe ...
- MySQL 之单表查询(精简笔记)
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RD ...
- iOS 常用命令行工具总结
平时工作中会经常用到命令行工具Command Lines Tool.而Command Line Tool本质是一个命令行工具包,内部有很多有用的工具,如Apple LLVM compiler.Make ...
- 基于Wireshark的ARP协议分析和IP报文、ICMP报文的分析|网络数据抓包|课程设计|traceroute|ping|
前言 那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助. 高质量博客汇总https://blog.cs ...
- 【奶奶看了都会】ComfyUI+SVD制作AI视频教程,附效果演示
AI一天,人间一年 大家好啊,我是小卷,最近AI绘画又发展出一些新玩意了,小卷因为工作的关系有一个月没关注AI的发展了,都有点跟不上版本节奏了... 1.comfyui的使用效果 今天给大家介绍下AI ...
- .NET 大数据实时计算--学习笔记
摘要 纯 .Net 自研大数据实时计算平台,在中通快递服务数百亿包裹,处理数据万亿计!将分享大数据如何落地以及设计思路,技术重难点. 目录 背景介绍 计算平台架构 项目实战 背景介绍 计算平台架构 分 ...
- Python 字典与集合
字典(Dictionary) 字典介绍 字典是"键值对"的无序可变序列,字典中的每个元素都是一个"键值对",包含:"键对象"和"值 ...
- Codeforces Round #821 (Div. 2) A-E
比赛链接 A 题解 知识点:贪心. 下标模 \(k\) 相同分为一组,共有 \(k\) 组,组间不能互换,组内任意互换. 题目要求连续 \(k\) 个数字,一定能包括所有的 \(k\) 组,现在只要在 ...
- 服务器网卡,10GE设备相关笔记
连接线 铜线 六类线基本可以满足万兆, 万兆网络一般只在短程使用铜线, 或者完全不用铜线 光纤 根据带宽和距离, 分为OM2, OM3, OM4等, OM2一般用于千兆或者短距离万兆, 长距离万兆使用 ...
- Js中Reflect对象
Js中Reflect对象 Reflect是ES6起JavaScript内置的对象,提供拦截JavaScript操作的方法,这些方法与Proxy对象的handlers中的方法基本相同. 描述 Refle ...