Codeforces Round #426 (Div. 2) B. The Festive Evening
来源:互联网 发布:ubuntu 16.04重装unity 编辑:程序博客网 时间:2024/06/08 13:27
题目链接:The Festive Evening
题目大意:给你一个n和k,代表一个长度为n的字符串,字符串只包含大写字母,26个大写字母代表26扇门,每扇门要等最后一个通过这扇门的客人走了之后才能关门,否则一定得有一个守卫在门前,关门后这个守卫可以到其他们去,问一共k个守卫能不能完成防守得目标
题目思路:记忆一下门最后关的时候是第几个客人,然后如果这个门没有守卫,外面首先要加一个守卫,然后判断一下守卫总数与k的大小关系,如果这个最后一扇,守卫数量减一,这样去强行判断一下就好了
#include <cstdio>#include <cmath>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;int main(){ int n,k,se[35]; string str; while(cin>>n>>k){ cin>>str; int cot = 0; int flag = 0; bool vis[35]; memset(vis,false,sizeof(vis)); for(int i = 0;i < n;i++) se[str[i]-'A'] = i; for(int i = 0;i < n;i++){ if(!vis[str[i]-'A']) vis[str[i]-'A'] = true,cot++; if(cot > k) {flag = 1;break;} if(i == se[str[i]-'A']) cot--; } if(flag == 0) puts("NO"); else puts("YES"); } return 0;}
阅读全文
0 0
- B. The Festive Evening(Codeforces Round #426 (Div. 2) B)
- 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) 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) B.The Festive Evening+C.The Meaningless Game
- Codeforces Round #426 (Div. 2) B. The Festive Evening(思维)
- #426 (Div. 2) B. The Festive Evening
- Codeforces Round 834B-The Festive Evening
- (模拟)Codeforces Round #426 B. The Festive Evening
- 【CodeForces】426Div2 B The Festive Evening
- CodeForces #426 div2 B The Festive Evening
- Codeforces 834B-The Festive Evening
- Codeforces 834 B The Festive Evening
- CodeForces 834B The Festive Evening
- The Festive Evening (Codeforces
- 用Kotlin写第一个Android程序
- Python数据工具箱:数据库连接库
- mysql5.7修改密码报错 Unknown column 'password'
- Android拨打电话
- Elasticsearch 分布式存储原理
- Codeforces Round #426 (Div. 2) B. The Festive Evening
- 找朋友
- Android animation动画效果笔记
- Black Hat 2017:需要当心的10大安全威胁
- GHGL项目总结-CA
- 格式化字符串与元组
- 无广告视频存储加速一整套免费视频服务(youku视频广告太长)
- linux系统下局域网内让电脑能够共享文件
- 登陆判断