CodeForces - 1082B Vova and Trophies
传送
题意:一个只包含G和S的字符串,一次交换能使连续的G最长为多少。
思路:想要使只包含G的子串最长,显然贪心地将两个子串中间的S与一个不在子串的G交换再与最大值比较就可以了,要注意除了这两个子串外还有没有多余的G可供交换。
代码:
#include <bits/stdc++.h>using namespace std;
typedef long long ll;
int n;
int tmp[100010];
string s;
int main() {scanf("%d", &n);cin >> s;int sum = 0;int cntg = 0, cnts = 0, tmpg = 0, ans = 0;int maxn = 0;for(int i = 0; i < n; i++) {if(s[i] == 'G') sum++;}for(int i = 0; i < n; i++) {if(s[i] == 'G') {cntg++;if(cnts) tmpg++;}else {cnts++;if(cnts == 2) {if(cntg == sum) maxn = max(maxn, cntg);else maxn = max(maxn, cntg + 1);cntg = tmpg;cnts = 1;tmpg = 0;}} }if(cntg == sum) maxn = max(maxn, cntg);else maxn = max(maxn, cntg + 1);printf("%d", maxn);return 0;
}
CodeForces - 1082B Vova and Trophies相关推荐
- CF 1082B Vova and Trophies
题目:Vova and Trophies 思路: 如果有两块G中间只隔一个S,就把它和一个G交换. 否则就移一个S到最长的那一块旁边. 代码: #include<bits/stdc++.h> ...
- 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 has won nn trophies in different competitions. Each trophy is either golden or silver. The ...
- Vova and Trophies _Codeforces 1082B
题目 Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The t ...
- Vova and Trophies
题意翻译 题目描述 你现在有 nn 枚奖牌,每枚奖牌为金牌或银牌.这些奖牌现在按顺序排成一排.现在你可以调换任意一对奖牌的位置,求金牌最长连续段. 输入格式 第一行一个整数 nn (2\le n\le ...
- B. Vova and Trophies
链接 [https://codeforces.com/contest/1082/problem/B] 题意 给你一个包含GS的字符串,只允许交换一次任意不同位置的字符,问最长的连续G串是多少 分析 很 ...
- Educational Codeforces Round 55 (Rated for Div. 2)
A.Vasya and Book 三种情况讨论一下 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 ...
- Codeforces 1092 D1 Great Vova Wall 题解
Codeforces 1092 D1 Great Vova Wall 题解 题目 题意 代码 思路 总结 题目 原题链接 题意 一组数字,要求在经过水平和垂直增加高度后所有数值大小一致,不能阶跃式增加 ...
- Codeforces Contest 1092 problem D1 Great Vova Wall (Version 1)
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, ...
最新文章
- java实现泛型顺序栈
- BZOJ3566 [SHOI2014]概率充电器 (树形DP概率DP)
- 使用@OrderBy对Spring Data MongoDB集合进行排序
- LwIP移植到FreeRTOS(STM32F107+DP83848)
- 元月元日是哪一天_2020年下元节是哪一天 几月几号
- python中使用什么关键字创建自定义函数_python自定义函数有哪些写法及用法
- 计算机课flash课件,flash课件在计算机教学过程中的应用
- 停车位配建标准:北上广深
- 期货日内交易小经验-开仓篇
- python 合并表格
- 筱筱看博客(简易的 loading 封装)
- 北京工作居住证续签流程条件及材料
- Windows xp .iso下载大全——超全面超难找的收藏版(二)
- 时间复杂度与大O记法的理解
- 题目: 哈夫曼编码大全
- 玉龙雪山景区完善视频监控设施打造智慧景区
- 品牌数字化升级,如何借力用户画像实现精准营销? - whale 帷幄
- Netty02-入门
- 用GPS模块校准系统时间
- 消防给水和消火栓系统(二)