题目链接:http://codeforces.com/contest/834/problem/B

题意:一共有26个门(A-Z表示),然后现在有n个人要走的门和k个守卫。每当有人要经过某个门时,门要一直打开直到最后一个要通过这扇门的人通过之后才关闭,并且在门打开的期间要有一个守卫看守,每个守卫只能看守一个门,当门关闭后守卫该门的守卫才能分配到其他的门。问你是否存在守卫不够用的情况。存在输出YES,否则输出NO。

思路:由于只有26个门,那么记录每个门打开的时间点和关闭的时间点。当遇到门打开的时,k-1,当遇到门关闭时k+1,如果存在k<0说明守卫不够用了。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long int LL;
const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
char str[MAXN];
int st[], ed[];
int main(){
int n, k;
while (~scanf("%d%d", &n,&k)){
scanf("%s", str);
for (int i = ; i < ; i++){
st[i] = ed[i] = -;
}
for (int i = ; i < n; i++){
if (st[str[i] - 'A'] == -){
st[str[i] - 'A'] = i;
ed[str[i] - 'A'] = i;
}
else{
ed[str[i] - 'A'] = max(ed[str[i]-'A'],i);
}
}
bool flag = true;
for (int i = ; i < n&&flag; i++){
if (st[str[i] - 'A'] == i){
k--;
if (k < ){ flag = false; }
}
if (ed[str[i] - 'A'] == i){
k++;
}
}
printf(flag ? "NO\n" : "YES\n");
}
return ;
}

Codeforces Round #426 (Div. 2) - B的更多相关文章

  1. CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)

    /* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...

  2. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  3. Codeforces Round #426 (Div. 2)

    http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...

  4. Codeforces Round #426 (Div. 2) C. The Meaningless Game

    C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...

  5. Codeforces Round #426 (Div. 2)A B C题+赛后小结

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  6. Codeforces Round #426 (Div. 2) A,B,C

    A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...

  7. Codeforces Round #426 (Div. 2)A题&&B题&&C题

    A. The Useless Toy:http://codeforces.com/contest/834/problem/A 题目意思:给你两个字符,还有一个n,问你旋转n次以后从字符a变成b,是顺时 ...

  8. 【Codeforces Round #426 (Div. 2) A】The Useless Toy

    [Link]:http://codeforces.com/contest/834/problem/A [Description] [Solution] 开个大小为4的常量字符数组; +n然后余4,-n ...

  9. 【Codeforces Round #426 (Div. 2) B】The Festive Evening

    [Link]:http://codeforces.com/contest/834/problem/B [Description] [Solution] 模拟水题; 注意一个字母单个出现的时候,结束和开 ...

  10. 【Codeforces Round #426 (Div. 2) C】The Meaningless Game

    [Link]:http://codeforces.com/contest/834/problem/C [Description] 有一个两人游戏游戏; 游戏包括多轮,每一轮都有一个数字k,赢的人把自己 ...

随机推荐

  1. 当遇到npm ERR! Unexpected end of JSON input while parsing near……时的解决办法

    运行npm install时有时会遇到以下错误: npm ERR! Unexpected end of JSON input while parsing near ... 这时可以先执行下面的命令: ...

  2. Getting CFNetwork SSLHandshake failed (-9806) error

    平常个人打测试包一切OK,今天突然不能联网了 How to handle "CFNetwork SSLHandshake failed" in iOS 参考1 Getting CF ...

  3. 【零售App】—— react/ant design mobile项目爬坑

    一.H5制作 - 图片文本的动画效果 bug:打开一个模板,添加图片,添加动画效果,若先选定动画效果,再调节动画时间和延迟时间,则动画和延迟时间没有改变:若先调节动画时间和延迟时间在选定动画效果,则动 ...

  4. java调用com组件com4j

    com4j A Java library that allows Java applications to seemlessly interoperate with Microsoft Compone ...

  5. 【MM系列】SAP 关于物料间的替代问题

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 关于物料间的替代问题   前 ...

  6. c#字符串代码,动态创建编译器

    https://www.cnblogs.com/mrma/p/3998679.html 试了,确实可行,在unity也能用 值得注意的是UnityScript.Scripting.Evaluator ...

  7. Web高效管理多个项目的SVN仓库

    转至:https://www.jianshu.com/p/a0af00642585 采用方案 Linux+Apache+Subversion+MySQL+JDK+Tomcat+Svnadmin 目录 ...

  8. ELk架构解析和部署

    目录 一.什么是elk. 1 二.ELK 常用架构及使用场景介绍... 2 1.最简单架构... 2 2.以Logstash 作为日志搜集器... 2 3.以Beats 作为日志搜集器... 3 4. ...

  9. 前端 CSS 盒子模型 目录

    CSS盒子模型介绍 padding border属性

  10. spring循环依赖是怎么解决的?

    回答:循环依赖就是循环引用,就是两个或多个Bean相互之间的持有对方,比如CircleA引用CircleB,CircleB引用CircleA,则它们最终反映为一个环. Spring如何解决循环依赖? ...