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. 即将开始的python之路

    准备开始学py 记录一下 加油

  2. 《Redis设计与实现》- AOF持久化

    1. AOF持久化 Redis AOF 持久化是通过保存Redis服务器所执行的写命令来记录数据库状态的. 2. RDB持久化与AOF持久化的区别 RDB持久化 RDB持久化通过保存数据中的键值对来记 ...

  3. 【转载】CentOS7.0下安装Telnet

    1..先检查CentOS7.0是否已经安装以下两个安装包:telnet-server.xinetd.命令如下: # rpm -qa telnet-server # rpm -qa xinetd 如果没 ...

  4. Python学习第一弹

    开发语言: 高级:Python.java.PHP  C#   GO  ruby   C++           ——>字节码   低级:C.汇编                          ...

  5. Permute Digits 915C

    You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...

  6. 二、mysql数据库之基本操作和存储引擎

    一.知识储备 数据库服务器:一台计算机(对内存要求比较高) 数据库管理系统:如mysql,是一个软件 数据库:oldboy_stu,相当于文件夹 表:student,scholl,class_list ...

  7. HEXO next live2d插件删除问题

    title: HEXO next live2d插件删除问题 date: 2018-03-06 13:09:12 updated: tags: [hexo,next,建站,学习,前端技术,疑问] des ...

  8. SDWebImage实现原理(怎么实现图片缓存器)

    入口 setImageWithURL:placeholderImage:options: 会先把 placeholderImage 显示,然后 SDWebImageManager 根据 URL 开始处 ...

  9. 22、(转载)jQueryMobile 知识点总结

    本文转自:http://www.cnblogs.com/jxyedu HTML5技术生态介绍 H5的现状与未来 HTML5是用于取代1999年所制定的 HTML 4.01 和 XHTML 1.0 标准 ...

  10. Percona-Tookit工具包之pt-heartbeat

      Preface       Replication delay is a common issue in MySQL replications.Especially in those replic ...