Codeforces Round #436 (Div. 2) B.Polycarp and Letters

因为难得又一次CF的比赛是非常清真的傍晚,超级少见啊

所以当然要打啦,于是rank:87,rating+=76,滞留在上紫的边缘

下面把几道觉得还不错的题目来总结一下

B.Polycarp and Letters

Polycarp 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.

input
11
aaaaBaabAbA
output
2
input
12
zACaAbbaazzC
output
3
Note

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.

一句话题意:让你选择最多的字母,使得这些字母都是不同的小写字母,并且它们在原串的位置之间没有大写字母。

我觉得就以这道题的难度都可以做A了吧

总之就是暴力,反正数据范围小,就算n^3的都没事(我打的就是这种辣鸡算法)

先枚举头和尾,然后在用bool数组来记录出现了那些小写字母,

然后的然后就可以A了啊,完全没有坑.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,ans,res;
 4 char s[1000];
 5 bool bo[1000];
 6 int main(){
 7     scanf("%d%s",&n,s+1);
 8     for (int i=1;i<=n;++i)
 9         for (int j=1;j<=n;++j){
10             ans=0; memset(bo,0,sizeof(bo));
11             for (int k=i;k<=j;++k){
12                 if (s[k]>='A'&&s[k]<='Z'){
13                     ans=0; break;
14                 }
15                 if (!bo[s[k]]) ans++,bo[s[k]]=1;
16                 res=max(res,ans);
17             }
18         }
19     printf("%d",res);    
20 }
View Code

 

posted @ 2017-09-29 19:57  logiccc  阅读(272)  评论(0编辑  收藏  举报