题意:给出一个字符串 只有G和S  可以交换任意两个位置的字符一次 问 最长的G的长度是多少

思路:预处理字符串 把相同的G粘成一个G 记一下数量  字符串变为 GSSGSGGSGSSG 相邻有一个S的即可粘在一起

这里要考虑字符串中有多少个部分G   假设有zz部分  如果zz 大于等于3 那么两个G移动后连在一起就是  num[i]+num[j]+1 如果ZZ只有2  那就是 num[j]+num[i]

这里要考虑初始化  初始化如果zz>=2  则初始化成 num[i]+1 否则就初始化成num[i]  (不然会WA13 别问我为什么知道的)

 #include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
char s[maxn],s2[maxn];
int num[maxn];
int main(){
int len;
scanf("%d",&len);
scanf("%s",s+);
//len=strlen(s+1);
int flag=;
int zz=;
int ans=;
for(int i=;i<=len;i++){
if(s[i]=='G'){
int cnt=;
while(cnt<=len&&s[i]=='G'){
cnt++;
i++;
}
zz++;
s2[flag]='G';
num[flag++]=cnt;
i--;
}
else {
s2[flag++]='S';
}
}
//for(int i=1;i<=flag-1;i++){
//cout<<s2[i]<<" "<<num[i]<<endl;
// } for(int i=;i<=flag-;i++){
if(zz<=)
ans=max(ans,num[i]);
else ans=max(ans,num[i]+);
if(i>=&&s2[i]=='G'&&s2[i-]=='S'&&s2[i-]=='G'){
if(zz>=)
ans=max(ans,num[i]+num[i-]+);
else ans=max(ans,num[i]+num[i-]);
}
}
cout<<ans<<endl;
return ;
}

B. Vova and Trophies 字符串预处理+思维+贪心的更多相关文章

  1. Vova and Trophies CodeForces - 1082B(思维题)

    Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...

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

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

  4. Codeforces 1082B Vova and Trophies(前缀+后缀)

    题目链接:Vova and Trophies 题意:给定长度为n的字符串s,字符串中只有G和S,只允许最多一次操作:任意位置的两个字符互换.求连续G的最长长度. 题解:维护pre和pr,nxt和nx. ...

  5. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  6. Educational Codeforces Round 55:B. Vova and Trophies

    B. Vova and Trophies 题目链接:https://codeforc.es/contest/1082/problem/B 题意: 给出一个“GS”串,有一次交换两个字母的机会,问最大的 ...

  7. 2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心

    2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心 [Proble ...

  8. E. The Contest ( 简单DP || 思维 + 贪心)

    传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ ...

  9. CF1082B Vova and Trophies 题解

    CF1082B Vova and Trophies 题解 瞎搞题,推荐的,一看是道水题,就随手A了-- 题目描述 Vova has won \(n\)trophies in different com ...

随机推荐

  1. CTSC 2018酱油记

    Day0 5.5 花了一上午的时间把codechef div2的前四题切了,又在zbq老司机的指导下把第五题切了 中午12:00 gryz电竞组从机房出发,临走的时候看到很多学长挺恋恋不舍的,毕竟可能 ...

  2. DVWA 黑客攻防演练(五)文件上传漏洞 File Upload

    说起文件上传漏洞 ,可谓是印象深刻.有次公司的网站突然访问不到了,同事去服务器看了一下.所有 webroot 文件夹下的所有文件都被重命名成其他文件,比如 jsp 文件变成 jsp.s ,以致于路径映 ...

  3. macos 安装sublime text 3,如何安装插件

    1. 上面的代码如下: import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1 ...

  4. UE4分支的Git Flow

    UE4作为开源商业引擎,其代码托管在私有库:https://github.com/EpicGames/UnrealEngine 为了能看到并下载UE4的代码,开发者需要有GitHub账号和Unreal ...

  5. DICOM中检查时间 CT和增强CT、MR和增强MR

    CT 的第一张到倒数第二张的时间0040,0002(ScheduledProcedureStepStartDate)DA:2008-10-27;0040,0003(ScheduledProcedure ...

  6. C# 不用递归,获取无限层级数据

    对象属性 public class ResList { public int ID { get; set; } public List<ResList> Child { get; set; ...

  7. c/c++ 网络编程 UDP 改变网关和网卡名字

    网络编程 UDP 改变网关和网卡名字 在程序里动态改变网关和网卡名字 1,改变网卡名字 #include <stdio.h> #include <string.h> #incl ...

  8. Windows server 2008R2远程桌面3389端口修改方法技巧

    windows server的服务器远程桌面默认端口号是3389,在工作中经常使用远程桌面连接服务器,但是这也是常常被黑客利用的端口号,但是如何修改掉默认端口,预防被黑客利用呢? 可以如下操作配置:很 ...

  9. 周一01.4安装PyCharm步骤

    安装集成开发工具 步骤一 步骤二 步骤三 步骤四

  10. docker容器日志收集方案(方案三 filebeat+journald本地日志收集)

    其实方案三和方案二日志采集套路一样,但是还是有点差别. 差别就在于日志格式如下: ​ 为了方便对比吧日志贴上来 Nov 16 10:51:58 localhost 939fe968a91d[4721] ...