题意:给出一个字符串 只有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 否则就初始化成…
Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap tw…
B. Vova and Trophies time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Vova has won n trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a r…
传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova has won nn trophies in different competitions. Each trophy is eit…
题目链接:Vova and Trophies 题意:给定长度为n的字符串s,字符串中只有G和S,只允许最多一次操作:任意位置的两个字符互换.求连续G的最长长度. 题解:维护pre和pr,nxt和nx.pre和nxt像连续子段和一样维护G的个数,pr和nx维护分别前面和后面各有多少个G. 遍历每个位置i,pre[i-1]+nxt[i+1],判断当前位置i能不能用多余的G来替换,pr和nx判断一下是否与pre和nxt相同即可,过程中更新答案. #include <cstdio> #include…
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the le…
B. Vova and Trophies 题目链接:https://codeforc.es/contest/1082/problem/B 题意: 给出一个“GS”串,有一次交换两个字母的机会,问最大的连续“G”串是多少. 题解: 在末尾后面放一个哨兵“S”,然后扫两遍,维护S左边和右边连续的“G”分别有多少个,然后求最大就可以了. 注意并不是所有的串都可以通过交换使长度变大这种情况,比如 “SGGGGS”,处理一下就好了. 代码如下: #include <bits/stdc++.h> usin…
2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心 [Problem Description] 有\(k\)种颜色,给你\(n\)个区间段,选择一种合适的方案给每个区间段染色,使得最终染色次数等于\(k\)次的长度和最大. [Solution] 将左右端点放在一起排序,但是标记出它是左端点,还是右端点,并且记录每个端点属于第几个区间,排序后,对于每个左端点,从未使…
传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ n 的一个前缀: c 中所有数 是 1 ~ n 的一个后缀. 剩下的都在 b 手上. 每次操作可以让一个人手上的一个数给另一个人. 解: 简单 DP : 显然就是问你 把  1 ~ n 分成三段的最少花费. 你把 第一个人 最初拥有的数, 所在的桶 定义为 0: 第二个人的为1, 第三个人的为2.…
CF1082B Vova and Trophies 题解 瞎搞题,推荐的,一看是道水题,就随手A了-- 题目描述 Vova has won \(n\)trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row. The beauty of the arrangement is the length of the longest subs…