[Codeforces] #436 B. Polycarp and Letters
B. Polycarp and Letters
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputPolycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from A in the string are all distinct and lowercase;
- there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
InputThe first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
OutputPrint maximum number of elements in pretty set of positions for string s.
Examples input11output
aaaaBaabAbA
2input
12output
zACaAbbaazzC
3input
3output
ABC
0Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
Analysis
该题题意非常之迷
首先给你个字符串,然后对该字符串进行信息统计
怎么个统计法呢
A 表示一个字符集
首先我们在他给的字符串(叫它 s 吧!)s里面随手画一个区间
这个区间需要满足:里面不包含大写字母
那么 A 保存的就是这个区间里含有的字母种类数(显然最多有26个元素)
最后输出 A 所包含字符集可能的最多数量
显然开个桶然后 O(n) 即可
Code
#include<cstdio> #include<iostream> #include<bitset> using namespace std; bitset<100> buck; char ctr; int ans,n; int main(){ scanf("%d",&n); for(int i = 1;i <= n;i++){ cin >> ctr; if(ctr <= 'Z' && ctr >= 'A'){ ans = max(ans,(int)buck.count()); buck.reset(); }else{ buck.set((int)(ctr-'a')); } } ans = max(ans,(int)buck.count()); printf("%d",ans); return 0; }B. Polycarp and Letters
- codeforces 864B - Polycarp and Letters
- codeforces 864B 之 Polycarp and Letters
- codeforces 864B - Polycarp and Letters
- CodeForces 858D Polycarp's phone book(Trie)
- Codeforces 861 D Polycarp's phone book(字典树模板)
- Codeforces 723 C. Polycarp at the Radio
- codeforces 723C : Polycarp at the Radio
- [贪心] Codeforces 723C #375 (Div. 2) C. Polycarp at the Radio
- Codeforces 723C.Polycarp at the Radio
- CodeForces 858C Did you mean... 、 CodeForces 858D Polycarp's phone book!黑科技
- 【codeforces 723 C】【暴力】C. Polycarp at the Radio【1~m中最少的数尽量多】
- codeforces 727F. Polycarp's problems
- codeforces723C- Polycarp at the Radio-greedy
- CodeForces-1006B-Polycarp's Practice
- codeforces 589 C. Polycarp's Masterpiece
- [Codeforces] #436 A. Fair Game
- Codeforces 861 D. Polycarp's phone book (trie)
- 【Codeforces 723C】Polycarp at the Radio 贪心
- [Codeforces] #436 C. Bus
- Polycarp and Letters