Codeforces Round #442 (Div. 2) B. Nikita and string

题意:求最长可以分a b a为三部分子串,a b a可以为空
思路在代码里
1 #include<cstdio>
2 #include<iostream>
3 #include<cstring>
4 #include<cmath>
5 #include<algorithm>
6 #define maxn 505
7 using namespace std;
8 int main(){
9 char a[5001];
10 int b[5001],c[5001];
11 cin>>a+1;
12 int t=strlen(a+1);
13 for(int i=1;i<=t;i++){
14 b[i]=b[i-1]+(a[i]=='a');//前i个a的个数
15 c[i]=c[i-1]+(a[i]=='b');//前i个b的个数
16 }
17 int ans=0;
18 for(int i=0;i<=t;i++){//为什么不从1开始,因为aba有空串情况
19 for(int j=i;j<=t;j++){
20 ans=max(ans,b[i]+c[j]-c[i]+b[t]-b[j]);//(前i个a的个数)+(i到j的b的个数)+(j到t的a的个数)
21 }
22 }
23 cout<<ans;
24 return 0;
25 }

Codeforces Round #442 (Div. 2) B. Nikita and string的更多相关文章
- Codeforces Round #877 (Div. 2) B. - Nikita and string
题目链接:http://codeforces.com/contest/877/problem/B Nikita and string time limit per test2 seconds memo ...
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
- Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和
Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
- Codeforces Round #442 Div.2 A B C D E
A. Alex and broken contest 题意 判断一个字符串内出现五个给定的子串多少次. Code #include <bits/stdc++.h> char s[110]; ...
- Codeforces Round #442 (Div. 2)
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #442 (Div. 2)A,B,C,D,E(STL,dp,贪心,bfs,dfs序+线段树)
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #442 (Div. 2) B题【一道模拟题QAQ】
B. Nikita and string One day Nikita found the string containing letters "a" and "b&qu ...
- 【Codeforces Round #442 (Div. 2) B】Nikita and string
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举中间那一段从哪里开始.哪里结束就好 注意为空的话,就全是a. 用前缀和优化一下. [代码] #include <bits/ ...
随机推荐
- 转换流的原理和OutputStreamWriter介绍&代码实现
转换流的原理 OutputStreamWriter介绍&代码实现 package com.yang.Test.ReverseStream; import java.io.FileNotFoun ...
- PLC中增益和偏移
y=kx+b这个直线方程,那么增益就是指k这个斜率,而偏移就是指b. 模拟量转换时一般是不需要设置这两个参数的,只有当外部信号与模块接收的信号在值上有偏差的情况下才会去调整这个参数. 如果的模块信号是 ...
- LuoguP5201 [USACO19JAN]Shortcut(最短路树)
字典序?建树时从小枚举,用\(Dijkstra\)的血泪建好树,\(size\)大小决定贡献 #include <iostream> #include <cstdio> #in ...
- Luogu3802 小魔女帕琪 (排列组合)
注意除数为0情况 #include <iostream> #include <cstdio> #include <cstring> #include <alg ...
- Linux 07 用户组文件
参考源 https://www.bilibili.com/video/BV187411y7hF?spm_id_from=333.999.0.0 版本 本文章基于 CentOS 7.6 概述 用户组的所 ...
- java-Collection,List简单使用与方法/(集合使用-中)
1.1集合只存放引用类型的元素并且集合存放的时元素的引用(地址)1.2新循环遍历集合 Collection c = new ArrayList(); c.add("one"); c ...
- 【建议收藏】Mac VMWare NAT模式安装 CentOS 7-操作教程
学习大数据离不开 Linux 系统,网络上大部分文章都是在 Windows 系统下使用 VMWare Workstation 安装 CentOS ,并使用 NAT 模式配置网络.本文基于 Mac OS ...
- Spark基础入门(01)—RDD
1,基本概念 RDD(Resilient Distributed Dataset) :弹性分布式数据集 它是Spark中最基本的数据抽象,是编写Spark程序的基础.简单的来讲,一个Spark程序可以 ...
- linux 的文件权限案列
需求: 技术部门人员可以相互查看,但不能删除和修改别人的文件,其他部门人员不能查看,但领导组可以且只能查看. 设计: 技术部: 组 jishu ; 人员 js1, js2 领导:组 lingd ; 人 ...
- Ubuntu20.04配置 ES7.17.0集群
Ubuntu20.04配置 ES7.17.0集群 ES能做什么? elasticsearch简写es,es是一个高扩展.开源的全文检索和分析引擎,它可以准实时地快速存储.搜索.分析海量的数据. Ubu ...