B. Vova and Trophies 字符串预处理+思维+贪心
题意:给出一个字符串 只有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 字符串预处理+思维+贪心的更多相关文章
- Vova and Trophies CodeForces - 1082B(思维题)
Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...
- 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 ...
- 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 ...
- Codeforces 1082B Vova and Trophies(前缀+后缀)
题目链接:Vova and Trophies 题意:给定长度为n的字符串s,字符串中只有G和S,只允许最多一次操作:任意位置的两个字符互换.求连续G的最长长度. 题解:维护pre和pr,nxt和nx. ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
- Educational Codeforces Round 55:B. Vova and Trophies
B. Vova and Trophies 题目链接:https://codeforc.es/contest/1082/problem/B 题意: 给出一个“GS”串,有一次交换两个字母的机会,问最大的 ...
- 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 ...
- E. The Contest ( 简单DP || 思维 + 贪心)
传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ ...
- CF1082B Vova and Trophies 题解
CF1082B Vova and Trophies 题解 瞎搞题,推荐的,一看是道水题,就随手A了-- 题目描述 Vova has won \(n\)trophies in different com ...
随机推荐
- loj#2531. 「CQOI2018」破解 D-H 协议(BSGS)
题意 题目链接 Sol 搞个BSGS板子出题人也是很棒棒哦 #include<bits/stdc++.h> #define Pair pair<int, int> #defin ...
- WebService访问oracle数据库本地调试
WebService访问oracle数据库本地调试-一步一个坑 上篇文章提到我们额数据库挂了,重装了数据库,然后呢我需要在本地调试WebService,看看那些数据结构缺失,迁移到新数据库中去.踩坑之 ...
- JSONObject.parseObject
{ "data":{ "shop_uid":"123"; “id”:"123" } } 将上面的json字符串转换为JS ...
- C# 发送电子邮件源码片段
下面代码内容是关于C# 发送电子邮件片段的代码,应该对各位有所用途. using System;using System.Web;using System.Web.Mail;public class ...
- Unity协程的坑
unity终止协程提供了 StopAllCoroutines() 和 StopCoroutines() 两个方法, 但是都只能终止该文件内的 IEnumerator. 并且具体使用有点坑, 见如下实 ...
- SqlServer sa 用户登录失败的解决方法
一.控制面板->服务->MS SQL SERVER->登录-->本地系统帐户-->重新启动MS SQL SERVER用windows验证登陆查询分析器-->执行 s ...
- BCP SQL导出EXCEL常见问题及解决方法;数据导出存储过程
一.‘xp_cmdshell’的启用 SQL Server阻止了对组件‘xp_cmdshell’的过程‘sys.xp_cmdshell’的访问.因为此组件已作为此服务嚣安全配置的一部分而被关 闭.系统 ...
- MFC拖拽、选择目录、遍历文件
1.选择目录 void CDecryptFileDlg::OnBnClickedSel() { std::wstring selectedDir; WCHAR szDir[MAX_PATH]; Zer ...
- table 的宽度设置无效
1.在table 标签添加样式 table-layout: fixed; 必须设置width的值:<table style="table-layout: fixed"> ...
- LV 指定或修改逻辑卷的major, minor号[RHEL6]
在创建逻辑卷时,可以指定逻辑卷的major和minor设备号. [-M|--persistent {y|n}] //Set to y to make the minor number specifie ...