Codeforces Round #426 (Div. 2) problem B
B. The Festive Eveningtime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
![]()
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.
InputTwo integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26).
In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.
OutputOutput «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower).
Examplesinput5 1
AABBBoutputNOinput5 1
ABABBoutputYESNoteIn the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.
题目大意:问是否有门没关,并且没人守卫的情况,如果有输出YES,否则输出NO。
思路:简单模拟。
1 #include<iostream>
2 #include<stdio.h>
3 using namespace std;
4 char num[1000050];
5 int men[26];
6 int flag[26];
7 int main()
8 {
9 int n,k;
10 cin>>n>>k;
11 scanf("%s",num+1);
12 for(int i=1;i<=n;i++){
13 men[num[i]-'A']++;
14 }
15 int sum=0,now;
16 for(int i=1;i<=n;i++){
17 now=num[i]-'A';
18 if(!flag[now]){
19 flag[now]=1;
20 sum++;
21 if(sum>k){
22 cout<<"YES"<<endl;
23 return 0;
24 }
25 }
26 men[now]--;
27 if(men[now]==0){
28 sum--;
29 }
30 }
31 cout<<"NO"<<endl;
32 return 0;
33 }
Codeforces Round #426 (Div. 2) problem 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 #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- 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 #753 (Div. 3), problem: (D) Blue-Red Permutation
还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门 Problem - D - Codeforces 题意 n个数字,n ...
- Codeforces Round #426 (Div. 2)
http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...
- Codeforces Round #426 (Div. 2) A,B,C
A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
随机推荐
- WPF使用Blazor的快速案例
下面我们将讲解在WPF中使用Blazor,并且使用Blazor做一些文件编辑操作,下面是需要用到的东西 WPF Blazor Masa Blazor Monaco 安装Masa Blazor模板 使用 ...
- 使用API接口获取淘宝商品数据的详细指南
在电商行业中,淘宝作为中国最大的在线购物平台,每天有数以百万计的商品被发布和交易.作为程序员,如果需要获取淘宝商品的详细数据,可以通过调用API接口来实现.本文将详细介绍如何使用淘宝API接口获取 ...
- ThreadLocal:线程中的全局变量
最近接了一个新需求,业务场景上需要在原有基础上新增2个字段,接口新增参数意味着很多类和方法的逻辑都需要改变,需要先判断是否属于该业务场景,再做对应的逻辑.原本的打算是在入口处新增变量,在操作数据的时候 ...
- Docker部署cas
一.首先安装cas镜像 1.拉取cas docker镜像 docker pull apereo/cas 2.启动容器: docker run --name cas -p 8443:8443 -p 8 ...
- iOS日志获取
IOS日志获取 崩溃日志存放目录: /var/mobile/Library/Logs/CrashReporter
- firefox对webview性能数据监控的模拟
现在为了降低手机端的开发成本,越来越多的手机应用采用html5在进行开发,这样可以保证一处开发,到处嵌入. 但是这样的手机性能经常会是个瓶颈,因为当体验要求变高时,大多依赖html渲染引擎来对dom数 ...
- Go语言中匿名嵌套和类型嵌套的区别
在Go语言中,匿名嵌套结构体和与类型同名的嵌套结构体不是完全等价的,它们有一些重要的区别.以下是它们之间的主要区别: 字段访问: 匿名嵌套结构体:当你使用匿名嵌套结构体时,内部结构体的字段可以被直接访 ...
- Text2Cypher:大语言模型驱动的图查询生成
话接上文<图技术在 LLM 下的应用:知识图谱驱动的大语言模型 Llama Index> 同大家简单介绍过 LLM 和图.知识图谱相关的结合,现在我来和大家分享下最新的成果.毕竟,从 GP ...
- 用 Dijkstra 算法解决最短路问题
话不多说,先看图 1.1 朴素版的Dijkstra算法 一般用到这个情况稠密图,也就是节点的个数比边的个数少. (稠密图用邻接矩阵存储) #include<cstring> #includ ...
- 基于.Net 的 AvaloniUI 多媒体播放器方案汇总
基于.Net 的 AvaloniUI 多媒体播放器方案汇总 摘要 随着国产化的推进,相信.Net的桌面端的小伙伴的可能已经有感受到了. 为了让.Net的桌面框架能够跨桌面平台,首选的就是Avalona ...