CF1399D Binary String To Subsequences

Codeforces Round #661 (Div. 3) A. Remove Smallest time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given the array a consisting of n positive (greater than zero) integers. In one move, you can choose two indices i and j (i≠ 阅读详情

原题链接:http://codeforces.com/problemset/problem/1399/D

Binary String To Subsequences

You are given a binary string s consisting of n zeros and ones.

Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the string belongs to exactly one subsequence and each subsequence looks like “010101 …” or “101010 …” (i.e. the subsequence should not contain two adjacent zeros or ones).

Recall that a subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. For example, subsequences of “1011101” are “0”, “1”, “11111”, “0111”, “101”, “1001”, but not “000”, “101010” and “11100”.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1≤t≤2⋅104) — the number of test cases. Then t test cases follow.

The first line of the test case contains one integer n (1≤n≤2⋅105) — the length of s. The second line of the test case contains n characters ‘0’ and ‘1’ — the string s.

It is guaranteed that the sum of n does not exceed 2⋅105 (∑n≤2⋅105).

Output

For each test case, print the answer: in the first line print one integer k (1≤k≤n) — the minimum number of subsequences you can divide the string s to. In the second line print n integers a1,a2,…,an (1≤ai≤k), where ai is the number of subsequence the i-th character of s belongs to.

If there are several answers, you can print any.

Example
input

4
4
0011
6
111111
5
10101
8
01010000

output

2
1 2 2 1
6
1 2 3 4 5 6
1
1 1 1 1 1
4
1 1 1 1 1 2 3 4

题目大意

ttt组询问,每组给出字符串的长度nnn以及一个长度为nnn的由000和111组成的二进制字符串。

要求将该二进制字符串分成尽可能少的、相邻字符不相同的子串。输出最少的子串数量以及每个字符所在子串的编号(此处允许存在多解)。

题解

我也不知道这是什么,或许算是一个朴素的贪心+++模拟?

显然,对于连续的相同字符,我们不可能将他们划分进同一个子串。

同时,为了使子串的数量最少,我们应该尽可能地把一段连续字符分别接入之前已经有的子串,只有当没有可供接入的子串(即最后一个字符与当前字符不同的子串)时,我们才新建一个以当前字符为结尾,长度为一的新子串。

我们要做的就是模拟上述过程,我们可以用两个桶来分别维护末尾为000和111的子串的编号,接入时将编号从一个桶转移到另一个桶,新建时直接往对应的桶里添加元素。

代码

因为询问有很多组,而我们的数组又因为题目要求得开的比较大,所以重置时不能使用memset\mathcal{memset}memset,而应手动清零,否则会TLE\mathcal{TLE}TLE。

(话说这套题的出题人是有多喜欢多组询问啊)

另外退役老咸鱼又重新找回了压行的感觉……

#include<bits/stdc++.h>
using namespace std;
const int M=2e5+5;
int t,n,tot,loc,num;
int buk[M],en[5][M],ans[M];
bool idx;
char bin[M];
void in(){scanf("%d%s",&n,bin);}
void re(){for(int i=0;i<=n;++i)buk[i]=ans[i]=en[0][i]=en[1][i]=0;}
void add(int l,int r){for(int i=l;i<=r;++i)ans[i]=++num,en[idx][++en[idx][0]]=num;}
void link(int l,int r){for(int i=l;i<=r;++i)en[idx][++en[idx][0]]=ans[i]=en[!idx][en[!idx][0]],en[!idx][0]--;}
void ac()
{
	idx=bin[0]-48,tot=1;
	for(int i=0;i<n;++i,++buk[tot])if(idx!=bin[i]-48)++tot,idx=bin[i]-48;
	idx=(bin[0]-48);
	loc=1,num=0;
	for(int i=1;i<=tot;loc+=buk[i],idx^=1,++i)
	if(buk[i]>en[!idx][0])add(loc+en[!idx][0],loc+buk[i]-1),link(loc,loc+en[!idx][0]-1);
	else link(loc,loc+buk[i]-1);
	printf("%d\n",num);
	for(int i=1;i<=n;++i)printf("%d ",ans[i]);putchar(10);
}
int main()
{
	scanf("%d",&t);
	for(int i=1;i<=t;++i)in(),re(),ac();
} 
LeetCode每日一题(Minimum Number of Flips to Make the Binary String Alternating) You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence: Type-1: Remove the character at the start of the string s and append it to the end of the string. Type-2: Pick any character in s and flip it 阅读详情

相关推荐

WVP+ZLM国标平台实战:从设备注册失败到视频播放黑屏,我遇到的5个典型问题与解法

部署WVP+ZLM国标视频平台时,设备注册失败、视频播放黑屏等问题常常让运维人员头疼不已。本文将基于真实运维场景,剖析五个最具代表性的故障案例,提供从网络配置到版本兼容性的全链路解决方案。

weixin_33178839的博客 362

Binary String To Subsequences

题目链接: Binary String To Subsequences 大致题意: 给定一个长度为n的二进制字符串, 现在需要你把他们拆分个一个个子序列, 要求每一个子序列都应当满足没有相邻的1且没有相邻的0. 例如0101…, 1010…是符合要求的. 问: 最少需要拆分成多少个子序列, 并且输出每一位应在哪个子序列中. 解题思路: 遍历整个字符串, 如果当前位是1, 则它一定需要放在某个以0结尾的字串后, 否则就要创建新的子序列. 我们不妨用两个队列分别存放以0和以1结尾的子序列编号, 每次查看对应的队

Fau的博客 530

【入门篇】第五章 第一次与 AI Agent 交互

本文介绍了OpenClaw中最基本的用户与AI Agent交互方式,剖析了Agent和Gateway两个核心组件的作用,通过简单示例展示了从用户请求到结果返回的完整执行流程,说明了最小交互过程对验证系统可用性的重要意义,为后续学习复杂任务执行机制奠定基础。

lanyv的博客 512

Binary String To Subsequences(子序列问题)

传送门 思路 不能有两个1挨着 ,也不能有两个0挨着,用两个容器存子序列的最后一个元素是第几个子序列里的,每当遇到一个0 尝试把它放到一个以1结尾的子序列末尾去,如果不行,就单独的为它开辟一个新的子序列,遇到1也是如此 code #include<bits/stdc++.h> using namespace std; int main() { int i,j,k,m,n,t; string a; std::ios::sync_with_stdio(0); cin.tie(0); ci

weixin_49865561的博客 265

SAP SD科目确定:从配置到凭证的财务集成核心

本文深入解析SAP SD科目确定的核心价值与配置实践,涵盖从主数据准备到财务凭证生成的全流程。通过六步配置法和KOFI00过程拆解,帮助企业实现销售与财务模块的高效集成,确保收入、成本等数据准确归集至对应会计科目,提升财务自动化水平与数据准确性。

weixin_33491377的博客 251

MaixCAM2 4K AI相机硬件解析与开发实战

嵌入式AI视觉开发中,边缘计算设备的选择直接影响项目落地效果。以NPU为核心的AI加速技术通过专用指令集优化,可在低功耗下实现10+TOPS算力,典型应用包括工业质检、智能门禁等实时场景。MaixCAM2作为新一代4K AI相机,搭载AX630 SoC芯片,其双核Cortex-A53与NPU的异构架构,在运行YOLOv11n模型时可达113FPS,显著优于传统方案。开发时需注意模型量化部署技巧,如INT8量化需500+张校准图片覆盖多光照条件,避免准确率下降。设备扩展性方面,PMOD接口支持热成像、ToF传

weixin_30819085的博客 691

【思维构造】Binary String To Subsequences—CF1399D

的子序列生成的字符串)中。这一点无疑很简单,只要某一个字符串结尾字符与。接到这个字符串的后边。如果所有字符串的结尾字符都与。结尾的字符串的编号。这里为了方便,使用动态数组。的时候,需要计算可以放入哪个字符串中(已经由。只记录所有字符串的末尾字符和这个字符串的编号。两种,所以我们使用两个数组,分别存储以。相同,那么只要再新开一个字符串,怎么用代码实现上边的过程呢?结尾的字符串的编号和以。

suoper2656的博客 168

Python 爬虫实战:爬取微博热搜与用户评论数据

本文系统讲解微博热搜榜单与用户评论数据的爬取技术方案。针对微博热搜榜采用Requests+BeautifulSoup解析静态HTML结构,实现高效爬取;对于动态加载的评论数据,使用Selenium模拟浏览器行为规避反爬机制。详细阐述技术选型、反爬策略、数据清洗及存储方法,提供完整代码实现和输出示例。同时强调合规要求,提示开发者需在遵守平台规则的前提下进行数据采集。该方案为舆情分析和热点研究提供了可落地的技术实现路径。

2503_91057718的博客 1717

D. Binary String To Subsequences(队列+模拟)

例如,"1011101 "的子序列是 "0"、"1"、"11111"、"0111"、"101"、"1001",但不是 "000"、"101010 "和 "11100"。你的任务是将给定的字符串划分为最少的子序列,使字符串的每个字符正好属于一个子序列,并且每个子序列看起来像 "010101... "或 "101010..." (也就是说,子序列不应包含两个相邻的零或一)。测试用例的第一行包含一个整数n(1≤n≤2⋅105)--s的长度。输入的第一行包含一个整数t(1≤t≤2⋅104)--测试案例的数量。

m0_64158084的博客 438

Android功耗系列专题理论之六:外设功耗问题分析方法

本文介绍了移动设备功耗问题的分析方法,重点针对传感器和GPU两大模块。传感器部分详细讲解了通过ADB命令获取日志、状态差异分析和单传感器隔离测试的排查方法,并给出优化建议。GPU部分从基础功耗测量、场景测试到功能模块拆解进行多维度分析。同时阐述了GNSS/GPS功耗的测试方法,包括前后台对比、星座双频拆解及SAP/DPO等特殊功能的电流分析,为移动设备功耗优化提供系统性的诊断思路。

374

Ubuntu开机进入initramfs,解决办法来了!

摘要:Ubuntu系统启动时卡在initramfs界面,表明系统无法正常挂载根文件系统。常见原因包括引导配置错误、文件系统损坏、驱动程序问题和硬件故障。解决方法包括:1)使用fsck修复文件系统;2)通过dmesg排查驱动问题;3)检查硬盘等硬件状态;4)重新安装GRUB引导程序。建议做好系统备份等预防措施,遇到问题时按步骤排查。该问题通常可通过文件系统修复或引导配置重建解决。(148字)

米可的博客! 3421

D. Binary String To Subsequences (div3) (字符串思维)

D. Binary String To Subsequences 题意: 给一个01串,要求拆分成尽量少的子序列,每个子序列满足01交替,例如:101010或者010101,输出子序列个数 及原串中每个字符所属的子序列编号。 思路: 由于字符串长度2e5,所以考虑 O(n) 或者 O(nlogn) 的做法。 我们考虑如何使得子序列最少:在遍历时当前位为1时,那么如果之前有以0结尾的子序列,那直接接上去,并且此子序列的末尾状态也改变了,否则重新另开一个子序列。 那么就可以用两个队列,动态的维护是否有以 0

Consult_ 461

ADS基础教程24 - Gerber文件的导入

一、引言二、基本概念1.仿真文件下载2.仿真文件介绍二、导入步骤1.新建workspace2.选择Layout结构3.导入设计4.选择文件类型5.导入文件6.预览文件内容7.铜皮离散问题四、总结选择。通过本文章结束,可以了解ADS中如何将导入Gerber文件,并且对导入的铜皮进行合并。下一步就针对导入的文件进行层叠设置和编辑。END!}}END!

XZ_ZC的博客 3057

题解 CF1399D 【Binary String To Subsequences】

题目链接:http://codeforces.com/contest/1399/problem/D 题目描述: You are given a binary string s consisting of n zeros and ones. Your task is to divide the given string into the minimum number of subsequ...

Acapplella的博客 427

VB摄像头监控

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

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

构造 / 贪心 - Binary String To Subsequences - CF 1399D

构造 / 贪心 - Binary String To Subsequences - CF 1399D 题意: 给定一个长度为 n 的 01 串,把它分成尽量少的子串,使得每一个子串不出现连续的 0 或 1。 求最少能够分成几组子串,并对于每一个字符,输出它们属于哪一组。 输出任意一组可行解。 Input The first line of the input contains one integer t (1≤t≤2⋅1041≤t≤2⋅10^41≤t≤2⋅104) — the number of test

njuptACMcxk的博客 409

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

CF1399D Binary String To Subsequences(思维)

题目传送门 淦,这道题TLE了不知道多少次呜呜呜 这道题呢首先你得看数据范围,因此下面的代码O(n)O(n)O(n)的时间复杂度你肯定过不了! #include<iostream> #include<stack> using namespace std; char a[2102100]; int ans[2102020]; int main(){ int T; cin>>T; while(T--){ int s; cin>>s; char u

m0_51841071的博客 134

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

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

【队列、模拟】CF #661 Div.3 1399D Binary String To Subsequences

队列、模拟 题意: 给出一串01序列,分割这一序列,使分割成的序列没有连续的0或1, 最少能分割成几个序列,并依次输出每个字符所在的序列编号 思路: 使用两个队列 q0, q1 分别存储 0 和 1 的下标, 使用数组 pos 存储第 i 个字符所在的子序列编号, 使用 num 记录当前子序列数量 遍历字符串,若字符为 0,则判断队列 q1 是否为空, - 若 q1 不为空,说明当前存在子序列以 1 结尾,不用另外开辟一个子序列,直接接上去就行了。(接上去的操作:取出 q1 队首元素的下标 id

qq_45958683的博客 344

CF1399-Codeforces Round #661 (Div. 3)-D. Binary String To Subsequences(构造、模拟)

题目链接 题意:给定一个01字符串,将其分成n个子序列,使得每个子序列都没有连续的0或1,问n的最小值和每一个字符所属的序列编号。 思路:使用两个队列q0,q1q0,q1q0,q1分别存储0和1的下标(同时两个队列的长度之差也体现了0和1的数量差),遍历字符串: 遇见’0’时,若q1为空则必须开辟一个新的子序列来存储这个多出来的’0’,若q1不为空,它就直接放到上一个1所在的子序列的后面,也就是子序列编号相同。 遇见’1’时同理 AC代码: #include<bits/stdc++.h>

Cain-James的博客 721

CF div3 D. Binary String To Subsequences

题目 题目链接:https://codeforces.ml/contest/1399/problem/D 题目大意:输入一个字串s 将它的拆分成“0101010”的形式 求最少要拆成多少块 思路 5555我真是five为啥昨晚会卡这道题是因为熬夜熬久了越来越傻了吗 直接开两个队列存下前面出现的相反的数字的位置 就OK了 代码 #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib&gt

kosf_的博客 375

D. Binary String To Subsequences

贪心的策略当然是能加就加进原本就有的,不能加的时候再重新开辟一个。这里用vector进行模拟,末尾存当前串的编号即可。

jisuanji2606414的博客 237

Codeforces1399D题解

题面 D. Binary String To Subsequences time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given a binary string s consisting of n zeros and ones. Your task is to divide the given string into the m

李田所的博客 479

Codeforces Round #712 (Div. 2)-ABC

A. Déjà Vu A palindrome is a string that reads the same backward as forward. For example, the strings “z”, “aaa”, “aba”, and “abccba” are palindromes, but “codeforces” and “ab” are not. You hate palindromes because they give you déjà vu. There is a string

lvy_yu_ET的博客 537

Codeforces Round #661 (Div. 3) D. Binary String To Subsequences(思维,字符串)

题目链接 题意: 给你一个01字符串,你能将他分为至少多少个相邻数字不同的子字符串,输出个数和每一个位置的字符属于哪个子串。 思路: 每次记录都从一段连续的0或1开始,a数组记录子串编号,b数组记录编号子串结尾为0还是1,对于每一段连续的0或1,都从编号为1的子串开始遍历,根据b数组判断最后一位的数字看他能否成为该编号子串的最后一位,如果可以就将a[i]变为该编号并改变b数组中该编号子串的结尾数字。 代码: #include<bits/stdc++.h> //#define int long l

ACkingdom的博客 442

Codeforces Round #661 (Div. 3) D. Binary String To Subsequences

Codeforces Round #661 (Div. 3) D. Binary String To Subsequences 题目链接 You are given a binary string s consisting of n zeros and ones. Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the st

旺崽的博客 2808

codeforce 1399D Binary String To Subsequences

题目 题意:给出一个长度为n的0、1组成的字符串,分为k个子字符串,使得每个子串没有连续的0、1,求k的最小值和子串的所属编号 思路:使用两个队列s0,s1分别存储0和1的下标(同时两个队列的长度之差也体现了0和1的数量差),遍历字符串:遇见’0’时,若s1为空则必须开辟一个新的子序列来存储这个多出来的’0’,若s1不为空,它就直接放到上一个1所在的子序列的后面,也就是子序列编号相同。遇见’1’时同理 AC代码: package 练习; import java.io.*; import java.math.

nankes的博客 265
上一篇: CF1399C Boats Competition
下一篇: CF1399E1 Weights Division (easy version)
ShadyPi
博客等级 码龄9年 1万+粉丝 637原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值