codeforces 538 B.Quasi Binary(思维题)

ThingsKit物联网平台产品管理之物模型 物模型是ThingsKit物联网平台为产品定义的数据模型,用于描述产品的功能。本文介绍物模型相关概念和使用限制。 阅读详情

B. Quasi Binary
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.

You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.

Input

The first line contains a single integer n (1 ≤ n ≤ 106).

Output

In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.

In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.

Sample test(s)
input
9
output
9
1 1 1 1 1 1 1 1 1 
input
32
output
3
10 11 11 

题目链接:http://codeforces.com/problemset/problem/538/B


题目大意:输入一个整数m,求相加和为m的多个只包含1、0的整数,要求这样整数个数最少。


解题思路:用字符数组输入,再转换为数组,每个数字大于1时减1并输出1,等于0时输出0。注意避免输出前导0。


代码如下:

#include <cstdio>
#include <cstring>
char s[8];
int a[8],b[8];
int main()
{
	int i,j,n,k,f=0,cnt=0;
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n;i++)
		b[i]=a[i]=s[i]-'0';
	for(j=0;j<n;j++)
	{
		if(b[j]==0)
			continue;
		while(b[j]>0)
		{
			for(k=j;k<n;k++)
			{
				if(b[k]>0)
					b[k]-=1;
			}
			cnt++;
		}
	}
	printf("%d\n",cnt);
	for(j=0;j<n;j++)
	{
		if(a[j]==0)
			continue;
		while(a[j]>0)
		{
			if(f)
			printf(" ");
			f=1;
			for(k=j;k<n;k++)
			{
				if(a[k]>0)
				{
					a[k]-=1;
					printf("1");
				}
				else
					printf("0");
			}
			cnt++;
		}
	}
	return 0;
}


Ollama + OpenCLAW 在 Windows 系统的完整部署指南 Windows 部署优先选 WSL2,避免原生环境的权限/兼容性问题;网络问题通过“离线包+国内镜像”解决,版本问题通过升级 Node.js 解决;内存不足可切换轻量模型或增大 WSL2 内存分配;核心链路:Ollama(模型管理)→ Gateway(网关)→ OpenCLAW TUI(交互),各组件启动正常即可稳定使用。 阅读详情

相关推荐

用AI+Playwright实现零代码UI自动化测试:以登录页面为例的实战指南

本文详细介绍了如何利用AI与Playwright结合实现零代码UI自动化测试,特别以登录页面为例进行实战演示。通过自然语言描述生成测试脚本,大幅降低技术门槛,提升测试效率,并支持跨浏览器验证。适合非技术人员快速上手专业级自动化测试。

weixin_28842269的博客 411

CodeForces - 538B Quasi Binary

codeforces - 538b quasi binary

Lyriv的博客 555

Windows 10/11 注册表 ProfileImagePath 误改修复:3步恢复用户登录与数据安全

本文详细介绍了Windows 10/11系统中因误改注册表ProfileImagePath键值导致用户无法登录的修复方法。通过3个关键步骤,包括定位SID、安全修复注册表项及验证处理,帮助用户恢复登录并保障数据安全。特别强调了操作顺序的重要性以避免数据丢失,适用于各类Windows用户账户登录错误的紧急处理。

chuoshao2508的博客 411

codeforces 538B Quasi Binary

点击打开链接 B. Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A number is called quasibinar

zhang__liuchen的博客 392

【人工智能AI】是什么?

人工智能(Artificial Intelligence),英文缩写为AI。它是研究、开发用于模拟延伸和扩展人的智能的理论方法技术及应用系统的一门新的技术科学。(百度百科)人工智能的基本原理:机器从「特定的」大量数据中总结规律,形成某些「特定的知识」,然后将这种「知识」应用到现实场景中去解决实际问题。在这个基本原理的基础上,有3个特征:1、人工智能本质上是一种工具2、人工智能技能只能解决特定的问题,而不是什么都能做3、人工智能属于归纳逻辑,可以告诉你是什么,但是不能告诉你为什么。

KJCZ.AK的博客 2万+

微生物16S数据上传NCBI的SRA库

本篇内容仅包括:俺自己的实验收集了淡水、淡水沉积物、海水、海草附着微生物样品,测序所得的Fastq格式数据,在文章投稿发表时被要求数据需上传NCBI的SRA库,得到一个PRJNA2347899这样子的IDs。仅解决了这个上传过程!

Xf_Niu的博客 7449

CodeForces 538B Quasi Binary(简单数学)

B. Quasi Binary A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 a

nudt_oys的博客 603

StarRC:版本陈旧引发的多corner提取RC失败

运行StarRC提取多corner RC时会遇到提取失败的情况,当分次提取各个corner RC时却成功了,这种时候优先考虑nxtgrd版本陈旧的情况。解决办法是找到nxtgrd对应的itf文件,然后使用新版starrc去产生nxtgrd。debug方法也简单,在运行StarRC开始阶段会报告如下信息,就证明nxtgrd太老了。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 1838

!codeforces 538B-Quasi Binary-(思维)

题意:由01两个数字组成的十进制数,加起来等于n,求最少有多少个这样的数字 分析:灵活创新,思维转换;如:415=111+101+101+101+1,不用想什么十进制减法什么的 代码: #include using namespace std; int main() { char a[10]; int i=0,hight=0; while(cin>>a[i]) i++; for(in

关于学习本身 1148

YOLOv5 实现 10 种热力图可视化方式教程 | GradCAM XGradCAM ScoreCAM LayerCAM HiResCAM EigenCAM......

10 种热力图可视化方法 ,总有一款适合你

Coding... 5577

Python 爬虫实战:爬取评论数据做情感分析

摘要:本文介绍基于Python的京东商品评论爬取与情感分析全流程实现。通过Requests库抓取评论数据接口,结合JSON解析获取结构化评论信息。利用SnowNLP进行中文文本情感分析,量化用户评价的情感倾向(正面/负面/中性)。结果显示正面评论占比66.3%,负面评论13.3%,关键词分析发现"卡顿""发热"是主要负面因素。该方法可应用于产品优化、品牌管理等场景,为决策提供数据支持。

2503_91057718的博客 1713

CodeForces 538B Quasi Binary(不错的贪心题 进制想法)

题目思路:你现在有一些数叫quasibinary ,这些数仅由0 和1构成,如10,.101,0,1 现在给你k,你要用最少的quasibinary 数,加起来等于k,先输出个数,然后输出这些数是哪些. 一开始的思路比较挫,而且严重错误. 这边说一下正确的思维方法:由于我们有的数仅仅是0和1,所以这边假设4135,则至少要加5次.而且也只需要5次, 因为个位无论我们取什么,他每次都是1

Jason 1531

MATLAB基础应用精讲-【数模应用】信用评分模型(附R语言和python代码实现)

信用评分模型是近年来兴起的一种为了保障银行和其他金融部门的金融安全而设立的一种关于人身金融权限的划定模型。该模型指根据客户的信用历史资料,利用一定的信用评分模型,得到不同等级的信用分数,根据客户的信用分数,来决定客户所可以持有的金额权限,从而保证还款等业务的安全性。而随着在现代社会和公司中,贷款,信用卡的作用日渐突出,信用评分模型的发展前景不可估量。信贷风险是指借款人因偿还贷款或履行合同承诺而破产而产生损失的可能性。传统上,它与贷款人无法偿还所欠利息和本金、影响现金流和增加装配成本所产生的风险有关。

qq_36130719的博客 367

CodeForces - 538B Quasi Binary解题报告

题目大意:给你一个数 n ,让你用一类数的和来表示它,这些数要满足条件,只由0和1组成,问你最少需要多少个这类数才能表示这个 n 。

薛崇祥的博客 813

深度学习工具包 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")

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Codeforces 538 B. Quasi Binary

B. Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A number is calledquasibinary if its decimal...

weixin_30709929的博客 169

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

CodeForces 538 B.Quasi Binary(贪心)

Description 给出一个整数n,要求用m最少个数的只由0和1组成的数的和表示n Input 一个整数n Output 输出满足条件的数的个数m以及这m个数 Sample Input 9 Sample Output 1 1 1 1 1 1 1 1 1 Solution 贪心,尽量多用1,m就是n的各位数中的最大值 Code #include&lt;cstdio&...

ZSQ 985

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

模拟:Quasi Binary

codeforces 538B-Quasi Binary

广告位出租~ 752

codeforces #300 B. Quasi Binary

题目大意: 给定一个数字n 然后有很多个形如  1 10 101 10101 这样01组成的【十进制】数字, 记住,十进制! 问n,【最少】由哪些数字组成。 显然任何一个数字k,都可以由k个1组成。。。 这题要求用最少个数字组成。 思路: DP f[i]表示拼出i所用的最少的数字数量。 f[i] = min(f[j] + 1)

ACMer不要报考高校代码为13627的移通学院! 426

Codeforces - 538B - Quasi Binary

B. Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A number is called quasibinary if its decim

j6635788的博客 269

B. Quasi Binary

// Problem: B. Quasi Binary // Contest: Codeforces - Codeforces Round #300 // URL: https://codeforces.com/problemset/problem/538/B // Memory Limit: 256 MB // Time Limit: 2000 ms // 2022-03-20 15:01:24 // // Powered by CP Editor (https://cpeditor.org) #in

qq_28409093的博客 203

Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)

A. Cutting Banner time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output A large banner with word CODEFORCES...

weixin_33728268的博客 239

Codeforces Round #300 B. Quasi Binary 水题

B. Quasi Binary Time Limit: 1 SecMemory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/problem/B Description A number is called quasibinary if its decimal representation contains only...

weixin_30701521的博客 121

http://codeforces.com/problemset/problem/538/B Quasi Binary

为了尽可能减少数的个数,那么就要尽可能减少对于每一个位仍然还留有的个数,于是从高位开始,尽可能减少比当前位小的位数中数的大小。 #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;cstdio&gt; #include &lt;algorithm&gt; #include &lt;vector&gt; #include &...

Jack_zhuiyi的博客 388

贪心(3)其他问题

。。。

nameofcsdn的博客 1674
上一篇: codeforces 538 A.Cutting Banner
下一篇: poj 1088 滑雪(线性DP)
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值