Educational Codeforces Round 42 (Rated for Div. 2) B


B. Students in Railway Carriage
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are nn consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.

The university team for the Olympiad consists of aa student-programmers and bb student-athletes. Determine the largest number of students from all a+ba+b students, which you can put in the railway carriage so that:

  • no student-programmer is sitting next to the student-programmer;
  • and no student-athlete is sitting next to the student-athlete.

In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.

Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all).

Input

The first line contain three integers nn, aa and bb (1n21051≤n≤2⋅105, 0a,b21050≤a,b≤2⋅105, a+b>0a+b>0) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.

The second line contains a string with length nn, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member.

Output

Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.

Examples
input
Copy
5 1 1
*...*
output
Copy
2
input
Copy
6 2 3
*...*.
output
Copy
4
input
Copy
11 3 10
.*....**.*.
output
Copy
7
input
Copy
3 2 3
***
output
Copy
0
Note

In the first example you can put all student, for example, in the following way: *.AB*

In the second example you can put four students, for example, in the following way: *BAB*B

In the third example you can put seven students, for example, in the following way: B*ABAB**A*B

The letter A means a student-programmer, and the letter B — student-athlete.

题意:在一排座位上,有空位,有两种类型的人需要我们去给他们排座位,相同类型的人不能坐在一起,问最多可以坐多少个人

我觉得这是一个贪心模拟题,min(可用长度,a的人数) + min(b,长度) +min((剩余a+b) ,额外座位数),一开始wa了好多发是因为没有判断剩余的a和b哪个更加大、

所以这题的几个坑点是:1.从左到右每次排座位时要注意当前位置的左边

           2.要想坐最多的人就应该先排人数多的那一种类型

           3.要判断当前的a类型或b类型是否为0,提前判断

附上代码

#include <bits/stdc++.h>
using namespace std;
char s[200005];
int main(){
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    scanf("%s", s+1);
    int l = strlen(s+1);
    s[0] = '.';
    int ans = 0;
    for(int i=1;i<=l;i++){
        int mx = max(a, b);
        if(s[i] == '*') continue;
        if(a == 0 && b == 0) break;
        if(a == 0){
            if(s[i-1] == 'b') continue;
            s[i] = 'b';
            b--;
            ans++;
        }
        else if(b == 0){
            if(s[i-1] == 'a') continue;
            s[i] = 'a';
            a--;
            ans++;
        }
        else{
            if(mx == a){
                if(s[i-1] == 'a'){
                    s[i] = 'b';
                    b--;
                }
                else{
                    s[i] = 'a';
                    a--;
                }
                ans++;
            }
            else if(mx == b){
                if(s[i-1] == 'b'){
                    s[i] = 'a';
                    a--;
                }
                else{
                    s[i] = 'b';
                    b--;
                }
                ans++;
            }
        }
    }
    printf("%d\n", ans);
}
View Code

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号