Educational Codeforces Round 55 (Rated for Div. 2)B—— Vova and Trophies

Whiteying

2018-11-30 20:44:54

Personal

# 题目链接: http://codeforces.com/contest/1082/problem/B # 题意: 有n个金奖杯和银奖杯,在只移动一个奖杯的状态下求最大的连续金奖杯。 # 思路: ### (B题比A题简单多了 for循环处理 当读入的是金奖杯的话,a[ans]++ 当读入的是银奖杯的话,ans++ 找到最大的a[i]+a[i+1] 最后特判一下最大的数是不是所有的金奖杯的数,如果不是的话,就加一输出(即用一个银奖杯交换金奖杯) # AC代码: ``` #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> using namespace std; #include<algorithm> #include<queue> typedef long long ll; #include<vector> #define cin(n) scanf("%lld",&(n)) #define cout(n) printf("%lld",(n)) #define couc(c) printf("%c",(c)) #define coutn printf("\n") #define cout_ printf(" ") long long n; long long a[100005]; long long ans; int num; int maxx=0; bool cmp(int b,int c) { return b>c; } int main() { cin>>n; getchar(); for(int i=1;i<=n;i++) { char ch=getchar(); if(ch=='G') { a[ans]++; num++; } else if(ch=='S') ans++; } for(int i=0;i<n;i++) { if(a[i]+a[i+1]>maxx) maxx=a[i]+a[i+1]; } if(maxx!=num) maxx++; cout<<maxx<<endl; return 0; } ```