Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
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 length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement as beautiful as possible — that means, to maximize the length of the longest such subsegment.
Help Vova! Tell him the maximum possible beauty of the arrangement if he is allowed to do at most one swap.
Input
The first line contains one integer nn (2≤n≤1052≤n≤105) — the number of trophies.
The second line contains nn characters, each of them is either G or S. If the ii-th character is G, then the ii-th trophy is a golden one, otherwise it's a silver trophy.
Output
Examples
Input1
10
GGGSGGGSGG
Output1
7
Input2
4
GGGG
Output2
4
Input3
3
SSS
Output3
0
Note
In the first example Vova has to swap trophies with indices 44 and 1010. Thus he will obtain the sequence "GGGGGGGSGS", the length of the longest subsegment of golden trophies is 77.
In the second example Vova can make no swaps at all. The length of the longest subsegment of golden trophies in the sequence is 44.
In the third example Vova cannot do anything to make the length of the longest subsegment of golden trophies in the sequence greater than 00.

分析:
标准水题,真的是标准水题
but需要分类
分类还特别恶心
然后比赛ing被光荣的hack了
然后又wa了一堆
居然有三个点没有注意
当有多个连续区间时可以移动其他的来补充最长的使最长的+1
当没有连续区间时输出0
当有两个连续区间的时候同第一个点,可以移动其他的来补充最长的
hack代码:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#include <list>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define f(i,n) for(int i = 0; i < n; i ++)
#define LL long long
#define eps (1e-6)
using namespace std;
char a[];
int num[];
int main() {
int n ;
s(n);
ss(a)
re(num,);
int count0 = ;
f(i,n) {
if(a[i] == 'S') {
if(num[count0] != ) {
count0 += ;
} else {
count0 ++;
}
} else if(a[i] == 'G') {
num[count0] ++;
}
}
int count1 = ;
for(int i = ; i <= count0; i ++) {
if(num[i] != ) {
count1 ++;
}
}
if(count1 == ) {
for(int i = ; i <= count0; i ++) {
if(num[i] != ) {
p(num[i]) pn return ;
}
}
} else if(count1 == ) {
int maxi = ;
for(int i = ; i <= count0; i ++) {
if(num[i] != ) {
if(num[i] != && num[i+] == && num[i+] != ) {
p(num[i]+num[i+]) pn return ;
}
if(maxi < num[i]) {
maxi = num[i];
}
}
}
p(maxi) pn return ;
} else {
int maxi = ;
for(int i = ; i <= count0; i ++) {
if(num[i] != && num[i+] == && num[i+] != ) {
if(maxi < num[i]+num[i+]+) {
maxi = num[i]+num[i+]+;
}
}
}
p(maxi) pn return ;
} return ;
}


最后小小的皮了一下,wa on test193
附上标答和标解
1082B - Vova and Trophies
Let riri be the maximal segment of gold cups that begins in the cup ii. Let lili be the maximum segment of gold cups that ends in the cup ii. Also, let the total number of gold cups be cntGcntG.
Note that it makes no sense to change the cups of the same color. Then let's consider the silver cup, which will change with the gold cup, let its number be ii. Then if ri+1+li−1<cntGri+1+li−1<cntG, then we will update the answer with the value ri+1+li−1+1ri+1+li−1+1, and otherwise with the value ri+1+li−1ri+1+li−1. This will not work if all the cups are golden. In this case, the answer is nn.
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() { cin >> n >> s; vector <int> l(n), r(n);
for(int i = ; i < n; ++i){
if(s[i] == 'G'){
l[i] = ;
if(i > ) l[i] += l[i - ];
}
}
for(int i = n - ; i >= ; --i){
if(s[i] == 'G'){
r[i] = ;
if(i + < n) r[i] += r[i + ];
}
} int res = ;
int cntG = ;
for(int i = ; i < n; ++i)
cntG += s[i] == 'G'; for(int i = ; i < n; ++i){
if(s[i] == 'G') continue;
int nres = ;
if(i > ) nres += l[i - ];
if(i + < n) nres += r[i + ];
res = max(res, nres);
} res = min(res, cntG);
if(cntG == n) res = cntG;
cout << res << endl;
return ;
}
Codeforces 1082B Vova and Trophies 模拟,水题,坑 B的更多相关文章
- Codeforces 1082B Vova and Trophies(前缀+后缀)
题目链接:Vova and Trophies 题意:给定长度为n的字符串s,字符串中只有G和S,只允许最多一次操作:任意位置的两个字符互换.求连续G的最长长度. 题解:维护pre和pr,nxt和nx. ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
随机推荐
- dns缓存刷新时间是多久?dns本地缓存时间介绍
原文: http://www.winwin7.com/JC/4742.html dns缓存刷新时间是多久?一般来说,我们只知道DNS解析是互联网绝大多数应用的实际寻址方式,在我们打开某站点,DNS返回 ...
- .net 连接 Oracle 可能需要配置
D:\Program Files (x86)\Oracle Developer Tools for VS2013\network\admin\tnsnames.ora
- Django文件存储(一)默认存储系统
Django默认使用的文件存储系统'django.core.files.storage.FileSystemStorage'是一个本地存储系统,由settings中的DEFAULT_FILE_STOR ...
- PHP判断是手机端还是PC访问
function isMobile(){ $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ' ...
- Redis内存模型总结
一.Redis内存统计 在客户端通过redis-cli连接服务器后,通过info命令可以查看内存使用情况: info memory 返回结果中比较重要的几个说明如下: (1)used_memory:R ...
- js 模拟css3 动画2
<html> <head> <title> javaScript缓动入门 </title> </head> <body> < ...
- 关于six.with_metaclass(ABCMeta, object)的理解
在学习Python过程中,看到了生成虚基类的方式, class PeopleBase(six.with_metaclass(ABCMeta, object)): @abstractmethod def ...
- 360极速浏览器Onetab插件存储位置
OneTab 是一款 Chrome / Firefox 扩展,用来让那些打开了但是没有空看的标签页保存到后台列表,从而节省宝「贵」的内存资源,根据 Chrome 的内存消耗情况下来,可以达到 95% ...
- 译:SOS_SCHEDULER_YIELD类型等待在虚拟机环境中的增多
原文出处:Increased SOS_SCHEDULER_YIELD waits on virtual machines 注: 原文的用词是Increased,想译作增强(增长),或者加强,这么译起来 ...
- Java线程池ThreadPoolExecutor
线程池的好处 1. 降低资源的消耗 通过重复利用已创建的线程降低线程创建和销毁所造成的消耗 2. 提高响应速度 当任务到达时,任务可以不需要等到线程创建就能立即执行 3. 提高线程的可管理型 线程是稀 ...