题意:求最长可以分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的更多相关文章

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

  2. Codeforces Round #184 (Div. 2) E. Playing with String(博弈)

    题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...

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

  4. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

  5. Codeforces Round #442 Div.2 A B C D E

    A. Alex and broken contest 题意 判断一个字符串内出现五个给定的子串多少次. Code #include <bits/stdc++.h> char s[110]; ...

  6. Codeforces Round #442 (Div. 2)

    A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...

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

  8. Codeforces Round #442 (Div. 2) B题【一道模拟题QAQ】

    B. Nikita and string One day Nikita found the string containing letters "a" and "b&qu ...

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

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举中间那一段从哪里开始.哪里结束就好 注意为空的话,就全是a. 用前缀和优化一下. [代码] #include <bits/ ...

随机推荐

  1. 常用的函数式接口_Predicate接口和常用的函数式借楼_Predicate_默认方法and

    package com.yang.Test.PredicateStudy; import java.util.function.Predicate; /** * java.util.function. ...

  2. react 吸顶实现

    今天获取到一个需求,其实就是吸顶的需求,页面下滑,某一块dom隐藏时发生吸顶现象.这种特效其实老生常谈了,但是在这次做的时候,突发奇想,能否将其做成一个 hook ,从而实现出传递ref即可使得 do ...

  3. [b01lers2020]Welcome to Earth-1

    1.打开之后界面如下,查看源代码信息,发现chase文件,结果如下: 2.访问chase文件会一直跳转到die界面,那就只能抓包进行查看,发现leftt文件,结果如下: 3.访问leftt文件并查看源 ...

  4. 选择结构——嵌套 if 控制语句

    1.嵌套 if 控制语句 概念: 在 if 控制语句中又包含一个或多个 if 控制语句的简称为嵌套 if 控制语句.嵌套 if 控制语句可以通过外层语句和内层语句的协作,来增强程序的灵活性. 语法格式 ...

  5. Python 爬取汽车之家口碑数据

    本文仅供学习交流使用,如侵立删!联系方式见文末 汽车之家口碑数据 2021.8.3 更新 增加用户信息参数.认证车辆信息等 2021.3.24 更新 更新最新数据接口 2020.12.25 更新 添加 ...

  6. pytest-fixture执行顺序

    作用域-scope 作用域越大,越先执行,session>package>module>class>function. 是否自动调用fixture 自动调用(autouse=T ...

  7. HCIA-Datacom 3.4 实验四:实现VLAN间通信实验

    实验介绍: 划分VLAN后,不同VLAN的用户间不能二层互访,这样能起到隔离广播的作用.但实际应用中,不同VLAN的用户又常有互访的需求,此时就需要实现不同VLAN的用户互访,简称VLAN间互访.华为 ...

  8. jQuery 查找父元素的函数 parent 和 parents 的区别

    函数 描述 parent([expr]) 查找子节点childNode的父节点,不包括祖先节点 parents([expr]) 查找子节点childNode的父节点,包括祖先节点 Talk is ch ...

  9. vue-router4 |name的作用|query传参|parmas传参|动态路由参数|命名视图|别名alias|前置路由守卫|路由过渡效果|滚动行为

    vue-router4 出现 No match found for location with path "/" #### router/index.ts文件 import { c ...

  10. QtCreator使用AStyle配置VS默认编辑代码风格

    基础配置和下载 基础配置和下载,随便找一个教程就行 下面贴出我的配置 --style=allman indent=spaces=4 indent-switches indent-preproc-blo ...