codeforces 909 D. Colorful Points

Mplus—验证性因素分析(Confirmatory Factor Analysis, CFA) 介绍一阶和二阶验证性因素分析概况及在Mplus中的操作方法。 阅读详情

Description

You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don’t have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.

You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can’t perform it.

How many operations will you need to perform until the next operation does not have any points to delete?

Input

Input contains a single string of lowercase English letters ‘a’-‘z’. The letters give the points’ colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.

The number of the points is between 1 and 10 6 .

Output

Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.

Examples

Input
aabb
Output
2

Input
aabcaa
Output
1

Note

In the first test case, the first operation will delete two middle points and leave points “ab”, which will be deleted with the second operation. There will be no points left to apply the third operation to.

In the second test case, the first operation will delete the four points in the middle, leaving points “aa”. None of them have neighbors of other colors, so the second operation can’t be applied.


感谢下面的博主的倾情分析~

https://blog.youkuaiyun.com/haut_ykc/article/details/79325344?utm_source=debugrun&utm_medium=referral

题意:给一行由字母 a~z组成的字符串 ,如果有字母与旁边的字母不同,就把他们全部标记并删除,直到不存在这样的字母,求需要几次这样的操作。

分析:

  1. 形如aaaaaaaaaaaaa这样的连续片段,它的内部很长时间是不变的,扫描起来很费时,所以把字符串压缩为字符+长度的表达方式,比如把aaabbbbccc压缩为 {a, b, c} + {3, 4, 3},直接对变化的部分进行关注;
  2. 考虑在新的结构上完成减法,如果一个段和两个段相邻,那么一次操作以后这个段一定会减少两个,而最左边的段和最右边的段只会减少一个。一句话,长度数组首尾每次-1,中间每次-2;
  3. 每轮操作完以后,相邻关系和首尾关系发生变化,考虑更新段的位置。减完后将所有的段重新紧密的排列在一起并更新n。这里需要注意的是,可能会有相同字母的段需要合并到一起;
  4. 考虑什么时候停止。只要段的总个数大于2就将继续

#include<stdio.h>
//#include<iostream>
//using std::cin;
//using std::cout;
#include<algorithm>
using std::sort;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mabs(x) ((x)>0?(x):(0-(x)))
#define N_max 1000006

int n;
int cnt[N_max];
int f[N_max];
char d[N_max];
int idx;
void upd(int n) {
    if (cnt[n] > 0) {
        if (idx > 0 && d[n] == d[idx - 1]) {//相同的合并
            cnt[idx - 1] += cnt[n]; 
        }
        else{//不同的添在后面
        cnt[idx] = cnt[n];
        d[idx] = d[n];
        idx++;
        }
    }
}


int main() {
    char ch, last = '\0';
    for (n = 0; ~scanf("%c", &ch);)
    {
        if (ch == '\n') break;
        if (last == '\0') {
            last = ch;
            d[n] = ch;
            cnt[n]++;
            continue;
        }
        //压缩为字母+长度
        if (ch == last)cnt[n]++;
        else { cnt[++n] = 1; last = ch; d[n] = ch; }
    }++n;
    if (n == 1) { printf("0"); return 0; }

    int ans = 0, flag = 1;
    for (; flag;) {
        ++ans;
        //首段-1并更新位置
        idx = 0;
        cnt[0]--;
        upd(0);

        for (int i = 1; i < n - 1; ++i) { 
            //中间段-2并更新位置
            cnt[i] -= 2; upd(i);
        } 
        //尾端-1并更新位置
        cnt[n - 1]--;
        upd(n - 1);
        //更新段的个数
        n = idx;
        if (n <= 1)break;
    }
    printf("%d", ans);
}
初识数据之特征选择 【代码】初识数据之特征选择。 阅读详情

相关推荐

静态时序分析Static Timing Analysis1——STA概述、标准工艺库、时钟、IO约束的建立

简要介绍STA和标准工艺库内容,对时钟,IO等进行约束的指令介绍,PVT

qq_42135020的博客 7537

Colorful Subsequence

题目描述 You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 109+7. Two subsequences are considered different if their charact...

dctika1584的博客 278

Gartner《构建可扩展数据产品建设框架》心得

数据产品化:从概念到落地的实践指南 当前企业正从传统数据需求模式转向数据产品化新范式。本文系统阐述了数据产品的核心价值、定义分类和实施框架,指出成功关键是将数据包装为可复用、可扩展的产品。Gartner框架强调产品思维,提出4阶段12步实施路径,涵盖设计、工程、发布和监控全流程。文章特别提醒要避免7大常见误区,如简单重命名报表、忽视元数据治理等,建议采取MVP策略,90天内完成从价值验证到产品落地的闭环。实施中需平衡技术选型与业务需求,建立跨职能团队,并通过AARRR模型持续追踪产品价值。

2501_91410404的博客 1002

[CF909D]Colorful Points

竟然是一道模拟题?! 卡了我这么久……

七代目鸽影 250

数理金融学笔记 Chap2 二叉树模型Binomial

2 二叉树模型与期权定价 Binomial Model and Option Pricing 文章目录2 二叉树模型与期权定价 Binomial Model and Option Pricing单期二叉树模型 One-step Binomial Model风险与无风险资产单期二叉树模型与无套利条件无套利定价 No Arbitrage Pricing风险中性定价 Risk Neutral PricingDelta套期保值 Delta Hedging两期二叉树模型 Two-Step Binomial Model

weixin_66831131的博客 2387

qt实现程序密钥注册功能,MD5加密+AES加密,并实现一台电脑系统一个密钥

qt实现了一个给自己软件加密的功能。 原理是: 需要被注册的软件第一次运行的时候,在系统的注册表里面注册一个键值,如下: 这个值作为生成密钥的用户识别号,然后生成密钥文件key.db,把这个key.db文件放到软件执行目录下,即可完成软件的注册并正常使用软件。 软件第一次打开的界面及密钥生成工具软件界面如下: 将密钥生成工具软件生成的key.db放到软件执行目录下之后,软件即可正常使用,如下图: 代码使用了MD5加密 外加 AES加密, 解密和加密的核心代码如下: QSt.

weixin_43935474的博客 4127

Codeforces Round #455 (Div. 2)-D-Colorful Points(缩点模拟)

D. Colorful Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of points on a straight line. Each point has a color assigne...

信仰.的博客 573

AI与Agent赋能下的软件测试变革:面向未来测试工程师的工作方法论

AI Agent 软件测试 测试 software testing test

测试技师的自我修养 1231

CodeForces 909D Colorful Points

题解: 暴力,模拟。 把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可。 #include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; char s[maxn]; struct X { char id; int num; }p[maxn], q...

weixin_34144450的博客 188

AgentScope实战训练营:构建计划可视化管理和HITL的AI智能计划助手

本文基于AgentScope Java SDK和Spring Boot WebFlux,从零构建一个支持SSE流式对话、计划可视化管理和HITL的AI智能计划助手Web应用PlanNotebook。涵盖项目架构设计、ReActAgent初始化、自定义工具注册、Hook机制实现、SSE事件协议定义、前端流式渲染等核心技术点,提供完整可运行的代码示例和详细的REST API参考。

program哲学 396

Android CCodec (十一) Codec2Buffer BufferPool分析

1、序言 2、C2BlockPool分析 3、SimpleC2Component关于BlockingBlockPool的实现 4、总结

给大佬递杯卡布奇诺的博客 4021

Codeforces 909 D. Colorful Points (模拟)

题目链接: Colorful Points 题意:   给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符。例如:aabcaa 删除一次就变成了aa,就无法再删除了。题目要求所给出的字符串要操作几次后才无法操作。 题解:   可以把整个字符串化简为相邻字符都不同的串,把每个位置字符的个数记录下来,比如aaaabbbbccccdddd ->...

242

【图像超分】论文精读:Interpreting Super-Resolution Networks with Local Attribution Maps(LAM)

论文题目:Interpreting Super-Resolution Networks with Local Attribution Maps —— 用局部归因图解释超分辨率网络CVPR 2021!必读文章!必须会的可视化手段!很多文章中都会对比LAM!图像超分辨率 (SR) 技术发展迅速,受益于深度网络的发明及其连续突破。然而,众所周知,深度学习和深度神经网络很难解释。SR网络继承了这种神秘的性质,很少有作品试图理解它们。在本文中,我们对 SR 网络进行了归因分析。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 546

Codeforces909D Colorful Points(缩点)

http://codeforces.com/problemset/problem/909/D 直接模拟超时。要运用缩点的方法,把相同的一段缩成一点,记录有几个。 对于非首尾的缩点每次-2,首尾的-1。 注意strlen不要放循环里,因为这个超时找了好久。。 1 #include<iostream> 2 #include<cstdio> 3 #inclu...

weixin_30402343的博客 166

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Codeforces Round #455 (Div. 2) 909D. Colorful Points

题   OvOhttp://codeforces.com/contest/909/problem/D   CF 455 div2 D   CF 909D 解   算出模拟的复杂度之后就是一个很水的模拟题   把字符串按照类似于行程编码的方式来表示,例如把 aaaabbccc 表示成 [4*a] [2*b] [3*c] 这样的形式([4*a] 这个用一个结构体表示)   接下去就可以...

weixin_30690833的博客 125

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #455 (Div. 2)D. Colorful Points[模拟]

题目:http://codeforces.com/contest/909/problem/D 题意:每次操作可以选择任意个数的字母,只要那个字母和相邻的一个字母不相同,就可以删去自身和不相同的1或2个字母,问需要多少次操作使得无法继续删除。 分析:每次删除只能删除一个连续相同区段的左端点和右端点(除了序列两端),用pair存一个字母连续出现的长度,每次暴力扫,让序列两端的长度-1,剩下的长...

weixin_33701294的博客 169

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

CodeForces 909D

题意略。 思路: 将字符分桶,然后暴力去扫,扫完合并。假设有k个桶,每个桶里有n / k个数,那么我们应该要扫 n / (2 * k)次,每次的复杂度是k,最后算得复杂度是O(n)。 详见代码: #include<bits/stdc++.h> #define maxn 1000005 using namespace std; struct node{ i...

weixin_30881367的博客 183

codeforces909d 字符串模拟

题意:有一个字符串,如果一个字符和它相邻的字符是不同的话,就把它们都消除,问最多能进行几次操作。如aabb,能进行2次操作。 题 题解:先把相邻的同一种字符和它的个数数出来。然后进行模拟。每次模拟后,再进行合并。 #pragma warning(disable:4996) #include<iostream> #include<cstdio> #include&lt...

sunnyorrainy的博客 278

A. Ilya and a Colorful Walk

A. Ilya and a Colorful Walk time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya lives in a beautiful city of Chordalsk. There a...

shinian_acmer的博客鸭 452

M.Subsequence(南昌网络赛)

Give a stringSSandNNstringT_iTi​, determine whetherT_iTi​is a subsequence ofSS. If ti is subsequence ofSS, printYES,else printNO. If there is an array\lbrace K_1, K_2, K_3,\cdots, K_...

shinian_acmer的博客鸭 241

CodeForces 24C Sequence of points (几何)

题目类型  几何 题目意思 输入一个 解题方法 dp[i][j] -> 取完前 i 件物品后还可以免费取 j 件物品的最小花费 状态转移  不取第i件物品 dp[i][j-1] = min(dp[i][j-1], dp[i-1][j]  (因为取完前i-1个物品后如果还可以免费取其他j个物品的话 就可以把第i个物品取了变              

yunyouxi0's blog 1010

HDU 4399 Colorful Points [构造]

  一个序列长度为n的序列P(1,n),构造一个序列Q,长度为N并且由1~N组成。一开始Qn对在P1的位置,接下来每秒Q都会整体右移一个位置,直到2N秒后和P没有交集。Ai代表第i秒P和Q交集元素的个数,Bi代表位置重合并且元素相等的元素个数。令Ci=max(Ai-Bi),构造一个序列,使Ci最小。   Ci最小是N-sqrt(N),官方题解说的比较详细。构造序列这个地方看了半天才看明白他是怎么...

weixin_34107955的博客 196

【AGC016B】Colorful Hats【结论题】

结论题,一直在猜结论。 分几种情况讨论。 设maxnmaxnmaxn为看到数量的最大值,minnminnminn为看到数量的最小值。 1.maxn−minn&gt;11.maxn−minn&gt;11.maxn-minn>1 直接输出No。 2.maxn==minn2.maxn==minn2.maxn==minn (1)minn==n−1(1)minn==n−1(1)minn==n-1输...

2016gdgzoi471 491

2018年全国多校算法寒假训练营练习比赛(第四场)-E-通知小弟(强连通缩点)

题目链接:https://www.nowcoder.com/acm/contest/76#question题目描述:在战争时期,A国派出了许多间谍到其他国家去收集情报。因为间谍需要隐秘自己的身份,所以他们之间只是单向联系。所以,某个间谍只能单向联系到一部分的间谍。同时,间谍也不知道跟他联系的是谁。HA是间谍们的老大,但他也只能联系到部分的间谍。HA现在有一项命令有告诉所有的间谍。HA想要知道他至少...

信仰.的博客 529

Atcoder Grand Contest 031 简要题解

Colorful Subsequence 对于每种字符,其要么不选,要么选择一个,所以答案是 ∏(cnti−1)−1\prod (cnt_i-1)-1∏(cnti​−1)−1 。 #include &lt;bits/stdc++.h&gt; using namespace std; const int md = (int) 1e9 + 7; inline int mul(int x, int...

wxh010910 920

hdu3530Subsequence【单调队列优化dp】2010多校联合

Problem Description There is a sequence of integers. Your task is to find the longest subsequence that satisfies the following condition: the difference between the maximum element and the minimum el

MissZhou要努力 1676
上一篇: codeforces 909 C. Python Indentation
下一篇: codeforces 913 D. Too Easy Problems
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值