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. Centos7安装Mysql5.7并修改初始密码

    1.CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件. wget https://dev.mysql.com/get/mysql57-community-r ...

  2. PHP审计(一)

    一.php中常见的危险函数和审计要点 危险函数(功能过于强大)    参数是否外部可控,有没有正确的过滤. PHP获取外界传入参数是通过下面几个全局函数的形式,所以审计参数传入经常要和下面几个变量打交 ...

  3. 易语言制作的QQ聊天中常用的GIF图片【带源码下载】

    该软件调用网页实现表情包制作,使用了精益模块. 最近比较火的王境泽.张学友.切格瓦拉.为所欲为.今天星期五.黑人问号脸.偷电瓶车.诸葛孔明.金坷垃等都可以通过此软件在线制作属于你的表情包. 太困了懒得 ...

  4. Hive的数据库和表

    本文介绍一下Hive中的数据库(Database/Schema)和表(Table)的基础知识,由于篇幅原因,这里只是一些常用的.基础的. Hive的数据库和表 先看一张草图: Hive结构 从图上可以 ...

  5. 1014-32-首页13-cell的结构分析---导航栏中间title位置的按钮的尺寸设置---setFrame----

    #import "HWTitleButton.h" #define HWMargin 5 @implementation HWTitleButton - (id)initWithF ...

  6. C语言数组篇(三)字符空间 和 非字符空间

     一维数组和字符串         首先是字符数组(区别字符串) ] = {'a','b','c'}; //这只是单纯的字符数组,不是字符串          字符串最重要的标志就是结尾有一个'\0' ...

  7. c++ function和bind

    bind 定义在头文件 functional 里 template<typename _Func, typename... _BoundArgs> inline typename _Bin ...

  8. POJ:3421-X-factor Chains(因式分解)(全排列)

    X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7986 Accepted: 2546 Descr ...

  9. tar命令,vi编辑器

    一.将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖): [root@localhost /]# cat /etc/passwd /etc/group > 1.txt ...

  10. Wind Of Change

    Wind of change until the end  变革的风一直吹直至最后 You will see that I will be your friend 你会看见我成为你的朋友 If you ...