传送
题意:一个只包含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相关推荐

  1. CF 1082B Vova and Trophies

    题目:Vova and Trophies 思路: 如果有两块G中间只隔一个S,就把它和一个G交换. 否则就移一个S到最长的那一块旁边. 代码: #include<bits/stdc++.h> ...

  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. 【CodeForces - 1082B】Vova and Trophies (贪心模拟,暴力)

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

  4. Vova and Trophies _Codeforces 1082B

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

  5. Vova and Trophies

    题意翻译 题目描述 你现在有 nn 枚奖牌,每枚奖牌为金牌或银牌.这些奖牌现在按顺序排成一排.现在你可以调换任意一对奖牌的位置,求金牌最长连续段. 输入格式 第一行一个整数 nn (2\le n\le ...

  6. B. Vova and Trophies

    链接 [https://codeforces.com/contest/1082/problem/B] 题意 给你一个包含GS的字符串,只允许交换一次任意不同位置的字符,问最长的连续G串是多少 分析 很 ...

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

  8. Codeforces 1092 D1 Great Vova Wall 题解

    Codeforces 1092 D1 Great Vova Wall 题解 题目 题意 代码 思路 总结 题目 原题链接 题意 一组数字,要求在经过水平和垂直增加高度后所有数值大小一致,不能阶跃式增加 ...

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

最新文章

  1. java实现泛型顺序栈
  2. BZOJ3566 [SHOI2014]概率充电器 (树形DP概率DP)
  3. 使用@OrderBy对Spring Data MongoDB集合进行排序
  4. LwIP移植到FreeRTOS(STM32F107+DP83848)
  5. 元月元日是哪一天_2020年下元节是哪一天 几月几号
  6. python中使用什么关键字创建自定义函数_python自定义函数有哪些写法及用法
  7. 计算机课flash课件,flash课件在计算机教学过程中的应用
  8. 停车位配建标准:北上广深
  9. 期货日内交易小经验-开仓篇
  10. python 合并表格
  11. 筱筱看博客(简易的 loading 封装)
  12. 北京工作居住证续签流程条件及材料
  13. Windows xp .iso下载大全——超全面超难找的收藏版(二)
  14. 时间复杂度与大O记法的理解
  15. 题目: 哈夫曼编码大全
  16. 玉龙雪山景区完善视频监控设施打造智慧景区
  17. 品牌数字化升级,如何借力用户画像实现精准营销? - whale 帷幄
  18. Netty02-入门
  19. 用GPS模块校准系统时间
  20. 消防给水和消火栓系统(二)

热门文章

  1. 使用浏览器发送HTTP POST请求
  2. 不适合创业赚钱的十种人
  3. 如何删除计算机新用户名和密码是什么,如何清除电脑开机密码
  4. 隐藏应用,在应用列表里不显示
  5. 2.4 隐函数和参数方程的导数 相关变化率
  6. 自定义header-php跨域
  7. 华为OD机试 - 最多颜色的车辆(Java JS Python)
  8. 全国高校大数据师资培训感悟
  9. Mac版VirtualBox安装Centos 7.9 教程 完整版
  10. java poi在word文档中插入图片后文件无法打开