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 (1≤n≤2⋅1051≤n≤2⋅105, 0≤a,b≤2⋅1050≤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[];
int main(){
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
scanf("%s", s+);
int l = strlen(s+);
s[] = '.';
int ans = ;
for(int i=;i<=l;i++){
int mx = max(a, b);
if(s[i] == '*') continue;
if(a == && b == ) break;
if(a == ){
if(s[i-] == 'b') continue;
s[i] = 'b';
b--;
ans++;
}
else if(b == ){
if(s[i-] == 'a') continue;
s[i] = 'a';
a--;
ans++;
}
else{
if(mx == a){
if(s[i-] == 'a'){
s[i] = 'b';
b--;
}
else{
s[i] = 'a';
a--;
}
ans++;
}
else if(mx == b){
if(s[i-] == 'b'){
s[i] = 'a';
a--;
}
else{
s[i] = 'b';
b--;
}
ans++;
}
}
}
printf("%d\n", ans);
}

Educational Codeforces Round 42 (Rated for Div. 2) B的更多相关文章

  1. Educational Codeforces Round 42 (Rated for Div. 2) E. Byteland, Berland and Disputed Cities

    http://codeforces.com/contest/962/problem/E E. Byteland, Berland and Disputed Cities time limit per ...

  2. Educational Codeforces Round 42 (Rated for Div. 2) D. Merge Equals

    http://codeforces.com/contest/962/problem/D D. Merge Equals time limit per test 2 seconds memory lim ...

  3. Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges

    http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...

  4. Educational Codeforces Round 42 (Rated for Div. 2) C

    C. Make a Square time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. Educational Codeforces Round 42 (Rated for Div. 2) A

    A. Equator time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  6. D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))

    模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...

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

    A. Equator(模拟) 找权值的中位数,直接模拟.. 代码写的好丑qwq.. #include<cstdio> #include<cstring> #include< ...

  8. C Make a Square Educational Codeforces Round 42 (Rated for Div. 2) (暴力枚举,字符串匹配)

    C. Make a Square time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

  9. D Merge Equals Educational Codeforces Round 42 (Rated for Div. 2) (STL )

    D. Merge Equals time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

随机推荐

  1. JAVA实现RSA加密,非对称加密算法

    RSA.java package org.icesnow.jeasywx.util.security; import java.security.Key; import java.security.K ...

  2. MySQL数据库 : 查询语句,连接查询及外键约束

    查询指定字段        select 字段1,字段2 from 表名; 消除重复行(重复指的是结果集中的所有完全重复行)             select distinct 字段1,字段2.. ...

  3. python__系统 : socket_TCP补充,协程

    TCP 三次握手: SYN  -->  SYN+ACK  -->  ACK 四次挥手:  FIN --> ACK (FIN)  --> ACK TCP十种状态: LISTEN  ...

  4. nginx+php整合(是让nginx可以运行php,以及下载地址)

    下载地址: nginx:http://nginx.org/en/download.html PHP: https://windows.php.net/download/ 都是官网的自己选择版本 安装文 ...

  5. java中substring()、charAt()、indexOf() (2013-05-05-bd 写的日志迁移

    substring 1. public String substring(int beginIndex)     返回一个新的字符串,它是此字符串的一个子字符串, 该子字符串始于指定索引处的字符,一直 ...

  6. C++ 整型长度的获取 不同的系统

    不同的系统中,C++整型变量中的长度位数是不同的,通常,在老式的IBM PC中,int 的位数为16位(与short相同),而在WINDOWS XP,Win7,vax等很多其他的微型计算机中,为32位 ...

  7. 关于修改zeppelin的代码显示

    最近我在修改zeppelin(0.7版本)的源码相关的知识,目前做的工作是修改zeppelin的代码,为了让zeppelin可以可以在页面中显示数据集,并且在其数据库中存储式真实的路径1.如果我们要运 ...

  8. Python 装饰器执行顺序迷思

    Table of Contents 1. 探究多个装饰器执行顺序 1.1. 疑问 1.2. 函数和函数调用的区别 1.3. 装饰器函数在被装饰函数定义好后立即执行 1.4. 疑问的解释 2. 参考资料 ...

  9. Entity FrameWork和Dapper的使用

    EF是微软系列下的更正苗红的重量级的ORM框架,功能强大,操作数据库的时候几乎不用写sql,可以像写C#代码一样操作数据库,尤其支持多表关联操作的时候极为方便,但是生成的sql语句性能很差,实在不敢恭 ...

  10. 《Cracking the Coding Interview》——第9章:递归和动态规划——题目3

    2014-03-20 03:01 题目:给定一个已按升序排序的数组,找出是否有A[i] = i的情况出现. 解法1:如果元素不重复,是可以严格二分查找的. 代码: // 9.3 Given a uni ...