Codeforces Round #426 (Div. 2) - B
题目链接: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的更多相关文章
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
/* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...
- 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 ...
- Codeforces Round #426 (Div. 2)
http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...
- Codeforces Round #426 (Div. 2)A B C题+赛后小结
最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...
- Codeforces Round #426 (Div. 2) A,B,C
A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...
- Codeforces Round #426 (Div. 2)A题&&B题&&C题
A. The Useless Toy:http://codeforces.com/contest/834/problem/A 题目意思:给你两个字符,还有一个n,问你旋转n次以后从字符a变成b,是顺时 ...
- 【Codeforces Round #426 (Div. 2) A】The Useless Toy
[Link]:http://codeforces.com/contest/834/problem/A [Description] [Solution] 开个大小为4的常量字符数组; +n然后余4,-n ...
- 【Codeforces Round #426 (Div. 2) B】The Festive Evening
[Link]:http://codeforces.com/contest/834/problem/B [Description] [Solution] 模拟水题; 注意一个字母单个出现的时候,结束和开 ...
- 【Codeforces Round #426 (Div. 2) C】The Meaningless Game
[Link]:http://codeforces.com/contest/834/problem/C [Description] 有一个两人游戏游戏; 游戏包括多轮,每一轮都有一个数字k,赢的人把自己 ...
随机推荐
- vsCode格式化插件
ESlint:是用来统一JavaScript代码风格的工具,不包含css.html等. 背景 近来研究前端,然后一直在百度上找VScode格式化(ESlint)的插件,结果找了半天都不靠谱.目前没有一 ...
- css中如何使用border属性与display属性
border属性介绍 border属性设置元素边框. 边框3个要素如:粗细.线型.颜色. 边框线型属性值说明表如: 属性指 描述 none 定义无边框. hidden 与 "none&quo ...
- legend2---数据字段没有默认值错误:SQLSTATE[HY000]: General error: 1364 Field 'h_21_injury_limit' doesn't have a default value
legend2---数据字段没有默认值错误:SQLSTATE[HY000]: General error: 1364 Field 'h_21_injury_limit' doesn't have a ...
- Ansible安装及常用模块
配置文件:/etc/ansible/ansible.cfg 主机列表:/etc/ansible/hosts 安装anslibe wget -O /etc/yum.repos.d/epel.repo ...
- UNITY ET 框架
GITHUB上近3000星的开源框架,包括了服务器客户端,IL RUNTIME热等特点,对于新项目,值得拥有
- JS去重-删除连续重复的值
function removeRepetition(str) { var result = "", unStr; for(var i=0,len=str.length;i<l ...
- 阶段3 1.Mybatis_03.自定义Mybatis框架_7.自定义Mybatis的编码-实现基于注解配置的查询所有
注解的方式,这里进行修改.上面注释的是原来xml的方式. 在dao类里面加上注解 创建注解类 声明注解的生命周期为Runntime 改变注解出现的位置,在Mehtod方法上 写完之后这里就不报错了. ...
- Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib 的一种情形
没有引用任何.net 4.5的东西,也没有引用 Newtonsoft.dll,原因是引用了微软的tlb类型库,引用方法如 https://www.cnblogs.com/nanfei/p/108798 ...
- Jmeter---BeanShell 常用的 vars, get, props, put ,log用法
BeanShell介 BeanShell是用Java写成的,一个小型的.免费的.可以下载的.嵌入式的Java源代码解释器,具有对象脚本语言特性.本篇只记录一下基本的使用.有以下五个组件: Beansh ...
- 应用安全 - Web框架 - Apache Solr - 漏洞汇总
CVE-2019-12409 Date: // 类型: 配置不当导致远程代码执行 前置条件: 影响范围: Solr and for Linux Solr下载:https://www.apache.or ...