Codeforces Round #426 (Div. 2) B
来源:互联网 发布:大姨吗数据和美柚同步 编辑:程序博客网 时间:2024/06/06 01:08
题意:告诉你一个字符串,每一个字母都要有一个人守卫,如果字母没有了,那么守卫可以去保护下一个字母,问,当前守卫数量能不能保证,所有的字母都被保护。
思路:记录下到每一个字母所需要的最大守卫数量。 如果当前字母出现过了,并且cnt不为0,那么cnt–。 如果当前字母没出现过,那么ans++; 如果出现过的字母, cnt==0了,ans–;
#include<bits/stdc++.h>using namespace std;const int maxn=1e6+500;char str[maxn];int cnt[1000];bool vis[1000];int main(void){ memset(vis,false,sizeof(vis)); memset(cnt,0,sizeof(cnt)); int k,n; cin >> n >> k; scanf("%s",str+1); for(int i=1;i<=n;i++) cnt[str[i]]++; int ans=0; int maxx=-1; for(int i=1;i<=n;i++) { if(vis[str[i]]==false) cnt[str[i]]--,vis[str[i]]=true,ans++; else if(vis[str[i]]==true) cnt[str[i]]--; maxx=max(maxx,ans); //printf("ans=%d\n",ans); if(cnt[str[i]]==0) ans--; // 如果当前字母为0,那么需要的守卫数量-1 } if(maxx>k) printf("YES\n"); else printf("NO\n"); return 0;}
阅读全文
0 0
- Codeforces Round #426 (Div. 2) B
- Codeforces Round #426 (Div. 2)(A+B)
- B. The Festive Evening(Codeforces Round #426 (Div. 2) B)
- Codeforces Round #426 (Div. 2) B. The Festive Evening
- Codeforces Round #426 (Div. 2) A B C
- Codeforces Round #426 (Div. 2)-B. The Festive Evening
- Codeforces Round #426 (Div. 2) B The Festive Evening
- Codeforces Round #426 (Div. 2) A B C
- Codeforces Round #426 (Div. 2) B. The Festive Evening
- Codeforces Round #426 (Div. 2) B. The Festive Evening
- Codeforces Round #426 (Div. 2)B. The Festive Evening
- Codeforces Round #426 (Div. 2) A B C D E
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Windows下安装redis插件
- Mongo进阶--存储原理
- php的学习之路
- Android Seekbar的onProgressChanged监听回调之fromUser参数解析(源码层次)
- Android ListView工作原理完全解析,带你从源码的角度彻底理解
- Codeforces Round #426 (Div. 2) B
- iOS应用架构谈 view层的组织和调用方案
- logger.error完整打印错误堆栈信息
- 集合框架——HashMap练习
- Football数据集可视化处理——gephi可视化处理数据
- 脚本流程
- OpenGL: gluPerspective和gluLookAt的关系
- divided two integers
- zabbix