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

11aaaaBaabAbA

output

2

input

12zACaAbbaazzC

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 }

时间: 2024-10-05 22:41:36

Codeforces Round #436 (Div. 2) B.Polycarp and Letters的相关文章

Codeforces Round #436 (Div. 2)【A、B、C、D、E】

Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张卡片上都写有一个数,两个人每人选一个数,每人可以拿的卡片必须写有是自己选的数,问能否选择两个数使得两个人每人拿的卡片数一样多并且能拿光卡片.[就是看输入是不是只有两种数字] //:第一遍我看成字符串包含有选的数字也能拿,,这样写着居然过了..水题水题.. 1 #include<cstdio> 2

Codeforces Round #436 (Div. 2) C. Bus

Codeforces Round #436 (Div. 2) C. Bus A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the pointx = a, immediately turns back and then moves to the point x = 0. After re

Codeforces Round #253 (Div. 2) A. Anton and Letters

题目很简单,只需要注意带空格的输入用getline即可 #include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> using namespace std; int main(){ string str; getline(cin,str); set<char> a; for(int i= 1 ; i < s

Codeforces Round #436 (Div. 2) F Cities Excursions

题意是给你一个有向图,点n <= 3000, 边m <= 3000,从s到t的路径必须是最小字典序,q<=400000次询问,从s到t中路径第k个点是什么,否则输出-1. 7 7 51 22 31 33 44 55 34 61 4 22 6 11 7 31 3 21 3 5 解释下样例2-6. 2-6的路径为2-3-4-5-3-5-3...-5-6无限循环,所以可以当作这个路径不存在,所以为-1 1-3的路径为1-2-3 如果在线做复杂度肯定要高,把询问的边存储,枚举出发点离线解决 用v

【贪心】Codeforces Round #436 (Div. 2) D. Make a Permutation!

题意:给你一个长度为n的数组,每个元素都在1~n之间,要你改变最少的元素,使得它变成一个1~n的排列.在保证改动最少的基础上,要求字典序最小. 预处理cnt数组,cnt[i]代表i在原序列中出现的次数.b数组,代表没有出现过的数是哪些.b数组的长度就是答案. b数组是从小到大排好的,然后for循环b数组,同时用一个指针p指着a数组的当前位置,最开始指向开头,如果cnt[a[p]]==1,就向后跳,否则再看 是否b[i]<a[p]或者a[p]这个数是否已经出现过了(用个hav数组表示a[p]是否已

[Codeforces] Round #436 (Div. 2)

1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 5 int n,cnt,ans,A,B; 6 int buck[500]; 7 8 int main(){ 9 scanf("%d",&n); 10 11 for(int i = 1;i <= n;i++){ 12 cin >> cnt; 13 if(!buck[cnt]){ 14 ans++; 15 if(

Codeforces Round #436 (Div. 2) E. Fire

题意:给你n个需要救得东西,每个东西给出t,d,p,表示需要花费t时间,在d时间之前,价值为p,问救出最多价值,并把每个东西序号输出,比如  3  3  4 ,这就无法救出 思路:dp,dp[i][j]表示救出第i个花费j时间救出最大价值,dp[i][j]=max(dp[i][j],dp[i-1][j-a[i][d]]+a[i].val)(j<=2000),再记录个g[i][j]表示第i个东西在j时间是救出来的,然后倒推 1 #include<bits/stdc++.h> 2 using

Codeforces Round #434 (Div. 2)

Codeforces Round #434 (Div. 2) codeforces 858A. k-rounding[水] 题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0. 题解:答案就是10^k和n的最小公倍数. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 using namespace std; 6 typedef long

Codeforces Round #298 (Div. 2) A、B、C题

题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side