Educational Codeforces Round 42 (Rated for Div. 2) B
2 seconds
256 megabytes
standard input
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).
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.
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.
5 1 1
*...*
2
6 2 3
*...*.
4
11 3 10
.*....**.*.
7
3 2 3
***
0
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的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges
http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...
- 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 ...
- 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 ...
- D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))
模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...
- Educational Codeforces Round 42 (Rated for Div. 2)
A. Equator(模拟) 找权值的中位数,直接模拟.. 代码写的好丑qwq.. #include<cstdio> #include<cstring> #include< ...
- 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 ...
- 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 ...
随机推荐
- VS2013未能正确加载的问题【转载】
今天使用电脑,关机重启时,WINDOWS提示“正在配置中,请勿关机” 的提醒,等重启后,打开VS2013就提示了未加载成功的问题,如下图: 我的解决方法是:找到VS2013开发人员命令提示:在窗口中输 ...
- C语言结构体指针成员强制类型转换
#include <stdio.h> #include <stdlib.h> typedef struct ListElmt_ { void *data; struct Lis ...
- <Docker学习>4. docker容器的使用
简单的说, 容器是独立运行的一个或一组应用, 以及它们的运行态环境. 对应的, 虚拟机可以理解为模拟运行的一整套操作系统( 提供了运行态环境和其他系统环境) 和跑在上面的应用.容器的运行是基于镜像的. ...
- iOS-UICollectionViewController 介绍
废话不多说,列几个列子 (几种情况下的做法): 情景一: 介绍:1. 在UIViewController 上加 UICollectionView (用代码 创建 UICollectionView). ...
- 使用python制作神经网络——搭建框架
一.神经网络的大体结构可分为三个函数,分别如下: 1.初始化函数 设定输入层节点,隐藏层节点和输出层节点的数量. 2.训练 学习给定训练集样本后,优化权重. 3.查询 给定输入,从输出节点给出答案 所 ...
- L2-029 特立独行的幸福 (25 分)
L2-029 特立独行的幸福 (25 分) 对一个十进制数的各位数字做一次平方和,称作一次迭代.如果一个十进制数能通过若干次迭代得到 1,就称该数为幸福数.1 是一个幸福数.此外,例如 19 经过 ...
- ABAP自定义截取字符串长度函数
SAP 中strlen()只能计算字符串的个数,不能计算含有中文字符串的长度,如字符串“SAP大波霸”,strlen('SAP大波霸') = 6,其实真实长度为3+3*2 = 9.我们可以通过cl_a ...
- 理解canvas路径
canvas路径和ps里面的路径差不多,在进行图形绘制时,先绘制出来图形的路径,然后再描边或者填充. canvas路径还有子路径的概念,在某一时刻,canvas之中只能有一条路径存在,Canvas规范 ...
- P1783 海滩防御
P1783 海滩防御 题目描述 WLP同学最近迷上了一款网络联机对战游戏(终于知道为毛JOHNKRAM每天刷洛谷效率那么低了),但是他却为了这个游戏很苦恼,因为他在海边的造船厂和仓库总是被敌方派人偷袭 ...
- 什么是 IRC?
IRC是Internet Relay Chat 的英文缩写,中文一般称为互联网中继聊天.它是由芬兰人Jarkko Oikarinen于1988年首创的一种网络聊天协议.经过十年的发展,目前世界上有超过 ...