B. Vova and Trophies

题目链接:https://codeforc.es/contest/1082/problem/B

题意:

给出一个“GS”串,有一次交换两个字母的机会,问最大的连续“G”串是多少。

题解:

在末尾后面放一个哨兵“S”,然后扫两遍,维护S左边和右边连续的“G”分别有多少个,然后求最大就可以了。

注意并不是所有的串都可以通过交换使长度变大这种情况,比如 “SGGGGS”,处理一下就好了。

代码如下:

#include <bits/stdc++.h>
using namespace std; const int N = 1e5+;
char s[N];
int sum1[N],sum2[N]; int main(){
int n;
cin>>n;
scanf("%s",s);
int len = strlen(s),tot=;
s[len]='S';
for(int i=;i<=len;i++){
if(s[i]=='G') tot++;
else{
sum1[i]=tot;
tot=;
}
}
tot=;
for(int i=len;i>=;i--){
if(s[i]=='G') tot++;
else{
sum2[i]=tot;
tot=;
}
}
int ans=,cnt=;
for(int i=;i<=len;i++){
if(s[i]=='S') ans=max(ans,sum1[i]+sum2[i]);
else cnt++;
}
if(ans!=cnt) ans++; //处理一下
cout<<ans;
return ;
}

Educational Codeforces Round 55:B. Vova and Trophies的更多相关文章

  1. Educational Codeforces Round 55:A. Vasya and Book

    A. Vasya and Book 题目链接:https://codeforc.es/contest/1082/problem/A 题意: 给出n,x,y,d,x是起点,y是终点,d是可以跳的格数,注 ...

  2. Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies 【贪心 】

    传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds ...

  3. Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies (贪心+字符串)

    B. Vova and Trophies time limit per test2 seconds memory limit per test256 megabytes inputstandard i ...

  4. Codeforces 1082 B. Vova and Trophies-有坑 (Educational Codeforces Round 55 (Rated for Div. 2))

    B. Vova and Trophies time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. Educational Codeforces Round 55 (Rated for Div. 2) Solution

    A. Vasya and Book Solved. 三种方式取$Min$ #include <bits/stdc++.h> using namespace std; #define ll ...

  6. Educational Codeforces Round 55 题解

    题解 CF1082A [Vasya and Book] 史上最难A题,没有之一 从题意可以看出,翻到目标页只有三种办法 先从\(x\)到\(1\),再从\(1\)到\(y\) 先从\(x\)到\(n\ ...

  7. Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies

    传送门 https://www.cnblogs.com/violet-acmer/p/10035971.html 题意: Vova有n个奖杯,这n个奖杯全部是金奖或银奖,Vova将所有奖杯排成一排,你 ...

  8. Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency

    E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...

  9. Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph

    D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...

随机推荐

  1. 网站安全检测 漏洞检测 对thinkphp通杀漏洞利用与修复建议

    thinkphp在国内来说,很多站长以及平台都在使用这套开源的系统来建站,为什么会这么深受大家的喜欢,第一开源,便捷,高效,生成静态化html,第二框架性的易于开发php架构,很多第三方的插件以及第三 ...

  2. 洛谷U32670 小凯的数字(比赛)

    题目网址 https://www.luogu.org/problemnew/show/U32670 题目背景 NOIP2018 原创模拟题T1 NOIP DAY1 T1 or DAY 2 T1 难度 ...

  3. Spark Streaming实时处理应用

    1 框架一览   事件处理的架构图如下所示. 2 优化总结   当我们第一次部署整个方案时,kafka和flume组件都执行得非常好,但是spark streaming应用需要花费4-8分钟来处理单个 ...

  4. vue3.0 部署的基础流程

    1.创建vue.config.js 主要是负责做设置的 2.修改vue.config.js 参考官方说明: 注意:对于本地开发的同学要注意,你之前在处理网络请求时是在8080端口下请求,现在如果换成了 ...

  5. Kotlin的属性委托:无上下文情况下Android的赋值(KAD 15)

    作者:Antonio Leiva 时间:Mar 9, 2017 原文链接:https://antonioleiva.com/property-delegation-kotlin/ 如我们在前面文章中读 ...

  6. 把python脚本打包成win可执行文件

    前几天有个朋友找我写一点小东西,写好后把代码发他帮他搞了半天,结果愣是没听懂,就找到了这个办法. 1.导入pyinstaller包, pip install pyinstaller 2.进入到你需要打 ...

  7. 第二十四篇configparser(**)

    configparser模块 config:配置,parser:解析.字面意思理解configparser模块就是配置文件的解析模块. 来看一个好多软件的常见文档格式如下: [DEFAULT] # 标 ...

  8. Windows Server 2008 R2(x64) IIS7+PHP5(FastCGI)环境搭建

    相关软件下载: 1.PHP下载地址: http://windows.php.net/downloads/releases/php-5.4.4-nts-Win32-VC9-x86.zip 如果是win2 ...

  9. bzoj1367 可并堆

    题面 参考:<左偏树的特点及运用--黄河源> 我们将这个数列划为很多个互不相交的区间,每一段区间内的 \(b\) 是相等的,即 \(b[l[i]]=b[l[i]+1]=...=b[r[i] ...

  10. android问题笔记集

    开发工具:android studio2.2 调试:手机直连调试,版本(android6) 问题1: Error:Unable to start the daemon process. This pr ...