B. The Festive Evening(Codeforces Round #426 (Div. 2) B)
来源:互联网 发布:java最好的培训 编辑:程序博客网 时间:2024/05/21 21:44
题目大意,输入一堆大写字母,每个字符从第一次出现到最后一次出现的这段时间内需要一个守卫, 问你在给定k给守卫的条件下,总需求会不会超过k个守卫。
这是一道思维题, 只需要记录每个字母出现的第一次的位置,和最后一次的位置,求一次区间最大覆盖就行了,由于数据量很小, 可以直接暴力。 代码如下:
#include <iostream>#include <stdio.h>#include <cstring>#include <algorithm>using namespace std;#define Max_N (1000000+100)int n;int k;char door[Max_N];int flag1[27];int b[27];int e[27];int used[Max_N];int main(){ memset(flag1, 0, sizeof(flag1)); memset(b, -1, sizeof(b)); memset(e, -1, sizeof(e)); memset(used, 0, sizeof(used)); scanf("%d%d", &n, &k); cin >> door; int len = strlen(door); for (int i = 0; i < len; i++) { int num = door[i] - 'A'; if(!flag1[num]) { b[num] = i; e[num] = i; flag1[num] = 1; } else e[num] = i; } for (int i = 0; i < 26; i++) { if(b[i] == -1) continue; for (int j = b[i]; j <= e[i]; j++) used[j]++; } int sum = 0; for (int i = 0; i < len; i++) sum = max(used[i], sum); //cout << sum << endl; if (sum > k) cout << "YES" << endl; else cout << "NO" << endl; 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
- #426 (Div. 2) B. The Festive Evening
- Codeforces Round #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
- CodeForces 834 B.The Festive Evening(水~)
- 行驶证/驾驶证/身份证等证件识别技术
- Linux(Ubuntu16.0.4)下安装pycharm
- knockoutjs的foreach绑定应首先判断数组是否为空,否则会出错
- Java的重写与重载简析
- 数据结构 c语言 hash查找 链地址法实现
- B. The Festive Evening(Codeforces Round #426 (Div. 2) B)
- 感知机
- 这是标题
- TreeSet的自然排序和定制排序
- 数字和日期转换(Rand/Time)
- 730
- DS.Lab筆記
- 【搜索入门专题1】 hdu1242 J
- 算法四