CodeFroces 834B. The Festive Evening(暴力)
来源:互联网 发布:图片剪刀手软件 编辑:程序博客网 时间:2024/06/07 21:14
题意:给出26个门口,标号为A到Z,你有n个客人,每个客人都会去某个门进入城堡,每个门在需要进这个门的第一个人开始开着,到最后一个要进这个门的人才会关闭。如果某一时刻开着的门的数量超过k,那么就会有坏人溜进去城堡。问是否有这样不安全的时刻,有输出yes,否则输出no。
解法:只需要枚举一下26个字母的开始和结束的位置,存起来。然后再次枚举每一个时间点,看看是否会有超过k个门开着。
算算复杂度为O(n*k)。
代码如下:
#include<bits/stdc++.h>using namespace std;typedef pair<int, int> pii;vector <pii> v;int n, k, s, e;char str[1000005];int main() {cin >> n >> k;scanf("%s", str);for(int i = 'A'; i <= 'Z'; i++) {s = -1;for(int j = 0; j < n; j++) {if(str[j] == i) {s = j;break;}}if(s != -1) {for(int j = n - 1; j >= s; j--) {if(str[j] == i) {e = j;break;}}}if(s != -1)v.push_back(pii(s, e));}sort(v.begin(), v.end());bool flag = 0;int cnt;for(int i = 0; i < n; i++) {cnt = 0;for(int j = 0; j < v.size(); j++) {if(i >= v[j].first && i <= v[j].second)cnt++;}if(cnt > k)flag = 1;}if(flag) {cout << "YES\n"; } else {cout << "NO\n";}return 0;}
阅读全文
0 0
- CodeFroces 834B. The Festive Evening(暴力)
- Codeforces 834B-The Festive Evening
- Codeforces Round 834B-The Festive Evening
- Codeforces 834 B The Festive Evening
- CodeForces 834B The Festive Evening
- CF 834B-The Festive Evening
- codefores 834B The Festive Evening
- CF 834B The Festive Evening
- CodeForces 834 B.The Festive Evening(水~)
- 【CodeForces】426Div2 B The Festive Evening
- CodeForces #426 div2 B The Festive Evening
- #426 (Div. 2) B. The Festive Evening
- Codeforces834B The Festive Evening
- CF834B-The Festive Evening
- The Festive Evening map
- The Festive Evening
- The Festive Evening
- The Festive Evening (Codeforces
- 网站技术架构
- All for one,one for all——7月份英语总结
- 如何利用VS编译lua源码
- [bzoj1419]Red is good 期望DP
- Linux网络管理员不得不了解的系统目录/proc/sys/net/(网络配置)
- CodeFroces 834B. The Festive Evening(暴力)
- SEO:SEO优化总结
- Greenplum在企业生产中的最佳实践
- 使用ngrok工具映射到外网可访问
- 消息队列处理模式
- 量子支票--淘汰比特币们的新技术
- C++学习-I/O
- .NET C#到Java没那么难,DB篇
- CBoard框架使用总结三--AdminLTE可扩展性分析