poj 1426 Find The Multiple

POJ1426-Find The Multiple【BFS+同余模】 北大POJ1426-Find The Multiple【BFS+同余模】 解题报告+AC代码 立即下载

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
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111

题意: 给你一个数n,找到一个只含0和1的十进制数,使得该数能被n整除。

分析:

第一种解法: 能整除即m%n = 0. 

因为m只有0和1组成,即可以看作是由 1, 10 ,100, 1000, 100000.。。。组成的。

比如1010 = (1000+10)。

根据同余模定理,1010%n = (1000%n + 10%n)%n.

所以可以先打表 ,是10^0 打到10^100。

然后对于每个余数,我们可以选择加或不加,dfs一下就好。


第二种:

因为数据量较小,可以直接暴力bfs。


#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;

void bfs(int n)
{
    queue<long long> q;
    q.push(1);
    while(!q.empty()){
        long long temp = q.front();
        q.pop();
        if(temp % n == 0){
            cout << temp  << endl;
            break;
        }
        else{
            q.push(temp*10);
            q.push(temp*10+1);
        }
    }
}
int main()
{
    int n;
    while(cin >> n){
        if(n==0) break;
        bfs(n);
    }
}




#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;

int n;
int mod[150];
bool vis[100];
int suma;
bool dfs(int pos)
{
    if(pos == 0) return 0;
    if((suma+mod[pos])%n == 0){
        vis[pos] = 1;
        return 1;
    }
    suma += mod[pos];
    vis[pos] = 1;
    if(dfs(pos-1)){
        return 1;
    }
    suma -= mod[pos];
    vis[pos] = 0;
    if(dfs(pos-1)){
        return 1;
    }
    return 0;
}
int main()
{
    while(cin >> n){
        if(n==0) break;
        memset(vis,0,sizeof(vis));
        mod[1] = 1%n;
        mod[2] = 10%n;
        mod[3] = 100%n;
        for(int i=4;i<150;i++){
            mod[i] = (mod[i-1]*mod[2])%n;   //余数打表
        }
        int flag;
        for(int i=1;i<150;i++){
            suma = 0;
            if(dfs(i)){			// i表示,从1到i判断每个数加或不加。
                flag = i;
                break;
            }
        }
        for(int i=flag;i>0;i--){
            cout << vis[i];
        }
        cout << '\n';
    }
}


在Proteus中用80C51模拟4线SPI点亮OLED屏幕 在Proteus里用80C51模拟4线SPI控制OLED屏幕使其显示图案(汇编实现)。 阅读详情

相关推荐

利用LDA进行主题建模,用困惑度和一致性曲线选取最优主题数

如果困惑度和一致性曲线效果图较好,确定了主题数量后,再单独跑一下2里面的程序。2中topic为5是我主观设置的,不一定为最优。

m0_56327159的博客 4223

Given a positive integer n....

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...

大魚的个人博客,如有不足,欢迎指正。 2464

ADS使用Smith圆图进行阻抗匹配

在处理RF系统的实际应用问题时,总会遇到一些非常困难的工作,对各部分级联电路的不同阻抗进行匹配就是其中之一。一般情况下,需要进行匹配的电路包括天线与低噪声放大器(LNA)之间的匹配、功率放大器输出(RFOUT)与天线之间的匹配、LNA/VCO输出与混频器输入之间的匹配。匹配的目的是为了保证信号或能量有效地从“信号源”传送到“负载”。 阻抗匹配(impedance matching) 信号源内阻与所接传输线的特性阻抗大小相等且相位相同,或传输线的特性阻抗与所接负载阻抗的大小相等且相位相同,分别称为传输线的输

红茶绿茶和奶茶的博客 3万+

poj1426(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...

weixin_43965698的博客 332

从CAD到完美网格:HyperMesh几何清理全流程指南(2023最新版)

本文详细介绍了2023最新版HyperMesh在几何清理和网格划分方面的全流程操作指南。从CAD导入、几何修复到中面提取和网格生成,系统性地分享了实战验证的解决方案,帮助工程师高效处理复杂几何体,提升有限元模型质量。特别针对汽车和航空航天领域的常见问题,提供了智能化工具和优化技巧。

weixin_29306011的博客 224

手把手教你搭建工业级C#上位机:完整架构+通信+配置+日志,新手也能落地(附全套源码)

模型层是“数据容器”,统一数据格式,避免参数传递混乱。本文搭建的C#上位机,采用“分层+模块化”架构,解耦了UI、通信、配置、日志四大核心功能,不仅满足工业场景的基础需求,还为后续扩展打下基础。新手跟着步骤走,既能掌握上位机的核心开发技能,又能理解工业级项目的架构设计思路。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1154

POJ-1426-Find The Multiple(DFS)

Description 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 tha

好吗好的~的技术博客 649

即插即用系列(代码实践)| GRSL 2024 ARConv核心模块:自适应矩形卷积——专为遥感图像设计,打破固定方形卷积束缚

摘要: 本文提出了一种用于遥感图像处理的自适应矩形卷积模块(ARConv),解决了传统方形卷积核在处理复杂几何结构(如细长道路、密集建筑物)时导致的光谱混叠和边缘模糊问题。ARConv通过动态调整卷积核的长宽比和旋转角度,使卷积核形状与地物特征自适应匹配。该模块可即插即用于全色锐化、语义分割等遥感任务,有效提升边缘保持能力和光谱保真度。核心代码基于PyTorch实现,包含偏移量生成和几何变换逻辑,支持梯度缩放以稳定训练。

分享顶会顶刊论文即插即用模块 140

【简单搜索】 POJ 1426 Find the Multiple详解

Find The Multiple: 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

Qiuker_jl的博客 517

uniapp中使用canvas生成海报,并下载保存到手机相册

如下图,是在H5中,canvas生成后的效果,首先说明,H5不支持返回图片的临时路径,不能用于保存,APP端生成成功后,会返回图片的临时路径用来保存到相册。本地测试,用的网络图片,没有出现跨域的问题,APP端也正常显示。 完整代码:可以将整个代码复制到你得uniapp项目中直接运行。代码中做了详细的注册,关于API的用法,这里只标注的简单的提示,具体还是参考 官方链接uniapp-canvas吧 <template> <view class="demo"> <c.

sunluyi的博客 3万+

Python 爬虫实战:拼多多商品评论情感分析(含词云生成与差评预警)

在电商行业竞争日益激烈的当下,商家对商品评论的分析需求愈发迫切。通过 Python 爬虫收集拼多多商品评论,并结合情感分析、词云可视化及差评预警技术,商家可精准洞察消费者反馈,优化商品与服务。本文将深度剖析从爬虫搭建到数据挖掘的关键环节,助力读者构建全流程电商评论分析系统。

yansideyucsdn的博客 1450

POJ-1426

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...

qq_42964711的博客 852

HQChart实战教程21 - uniapp app端K线图定制tooltip

HQChart实战教程21 - uniapp app端K线图定制tooltip序效果步骤2. 注册标题绘制事件3. 标题绘制回调函数格式说明eventdataobjtooltip显示函数完整代码HQChart代码地址 序 hqchartK线图内置一个tooltip, 如果需要定制一个tooltip, 我们可以通过注册绘制标题事件,来自己做一个div显示数据。 参考教程HQChart实战教程7-自定义显示手势点击K线显示信息 效果 步骤 在外部创建一个view,并在view里创建需要显示的信息字段. 例子里

小银 2556

POJ 1426 Find The Multiple 简单dfs构造

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

zkpj12的博客 262

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

POJ1426 Find The Multiple

POJ1426 Find The Multiple题目描述 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

退役的铜牌狗 368

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ 1426 Find The Multiple

POJ 1426 Find The Multiple 题目链接http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only ...

weixin_30352191的博客 87

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

POJ.1426 Find The Multiple (BFS)

POJ.1426 Find The Multiple (BFS)题意分析给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数。思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个数字只能是1 * 10或者1 * 10 + 1。就按照这种方式枚举,依次放入队列,如果是其的倍数,就输出。一开始没理解题意,以为是找一个能整除的二进制数,错了半天。代码总览#include <cstdio>

Pengwill's Blog 354

POJ1426--Find The Multiple

POJ1426–Find The Multiple 目录POJ1426--Find The Multiple一、题目链接二、题目内容三、题意拆解四、解题思路五、参考代码 一、题目链接 POJ1426 二、题目内容 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

Verber的博客 792

【POJ】1426 Find The Multiple

题目链接:http://poj.org/problem?id=1426 题意:给定一个正整数n,找一个比n大且能只由01构成的且能够被n整除的数。 题解:这个就是在后面添0和添1小心试探。一定要是添0不成功再去添1。 代码: 1 #include<iostream> 2 #include<cstdio> 3 using na...

deze1991的专栏 170

poj 1426 Find The Multiple (bfs 搜索)

Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18012   Accepted: 7297   Special Judge Description Given a positive integer n, write a pr

Just do it ! 1787

POJ-1426 Find The Multiple

POJ-1426 Find The Multiple 题目链接:POJ-1426 题目大意:找到一个数 这个数只由1或0组成 且是给定数的整倍数 解题思路:只由1或者0组成 那么就从1为起点 每次乘10 或者乘10+1 就能覆盖到所有的数 BFS搜索即可 注意示例给定的不是最小解 不要被误导 代码块: #include<iostream> #include<queue> ...

鱼头的水题之路 215

POJ-1426 Find The Multiple

状压

Brust Link 930

E - Find The Multiple POJ - 1426

E - Find The MultiplePOJ - 1426 Find The Multiple 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. ...

qq_31267769的博客 283

Poj 1426 Find The Multiple

Poj 1426 Find The Multiple 题意 给一个数n(1 <= n <= 200),求它的非零倍数m, m 是一个仅含有1或0的十进制数,m不超过100位(十进制),求一个m值即可。 解题思路 这道题我读了几遍,竟然没读懂。知道题意就很简单了,BFS,从1开始暴力搜索。 代码 #include <stdio.h> #includ...

qq_33005379的博客 194
上一篇: poj3279 Fliptile 好题
下一篇: vim
mwhybmj
博客等级 码龄10年 8粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值