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,赢的人把自己 ...
随机推荐
- [NLP] nlp-lstm-cos -> sin
LSTM 看了官方lstm以及相关原理,然后自己按照理解写了一遍,然后在网上看到cos预测sin问题,然后用lstm完成了建模. 看到好多论文里图像文本特征用lstm的,对学ocr有点帮助. 官方ls ...
- leetcode-mid-Linked list- 200. Number of Islands¶
mycode 57.92% class Solution(object): def numIslands(self, grid): """ :type grid: Li ...
- Flask 中的蓝图
相当与django中的App 基础模板 1.初识Flask蓝图(blueprint) 创建一个项目然后将目录结构做成: s_view.py 文件中的内容 from flask import Blu ...
- 十七、RF中的等待时间
1.sleep:强制等待n秒 sleep 秒数 2.implicit wait 隐式等待 2.1 get selenium implicit wait :取隐式等待时间,隐式等待时间默认为0 2. ...
- 《Using Databases with Python》Week3 Data Models and Relational SQL 课堂笔记
Coursera课程<Using Databases with Python> 密歇根大学 Week3 Data Models and Relational SQL 15.4 Design ...
- jyputer notebook 、jypyter、IPython basics
1 .修改jupyter默认工作目录:打开cmd,在命令行下指定想要进的工作目录,即键入“cd d/ G:\0工作面试\学习记录”标红部分是想要进入的工作目录. 2.Tab补全 a.在命令行输入表达 ...
- ElasticSearch Machine Learning
https://www.youtube.com/watch?v=DBRISS0UKcA, 2017/04 Single Metric job: 我想按照 一定的time interval 去 aggr ...
- Flask(六)—— 自定义session
Flask(六)—— 自定义session import uuid import json from flask.sessions import SessionInterface from flask ...
- linux sed 命令 实现对文件的增删改替换查 实验
1. 统一实验文本 # 创建包含下面内容的文件,后面的操作都会使用这个文件 [root@MongoDB ~]# cat person.txt ,mike,CEO ,jack,CTO ,yy,CFO , ...
- springboot项目中使用maven resources
maven resource 组件可以把pom的变量替换到相关的resouces目录中的资源文件变量 示例项目:内容中心 (文章管理) 生成jar包,生成docker ,生成k8s文件 1.项目结构 ...