http://codeforces.com/contest/864/problem/B

题意:

给出一个字符串,要求找到一个集合S,使得从S中选出的所有数,在这些数的位置上的字母全部为小写且是不同的字母,并且任意在S中两个数i,j,对于i  <  j,从i到j的所有位置上都为小写字母。

思路:

找出所有的大写字母的位置,在任意两个“相邻”(指的是这两个大写字母的中间不存在大写字母)的大写字母中寻找S,这样就可以保证全部为小写字母,用set保存出现过的字母就可以了。

代码:

 #include <stdio.h>
#include <algorithm>
#include <set>
using namespace std; int pos[];
char a[]; set<int> s;
set<char> c; int main()
{
int n; scanf("%d",&n); scanf("%s",a); pos[] = -;
int cnt = ; for (int i = ;i < n;i++)
{
if (a[i] >= 'A' && a[i] <= 'Z')
{
pos[cnt++] = i;
}
} pos[cnt] = n; int ans = ; for (int i = ;i < cnt;i++)
{
c.clear();s.clear(); int st = pos[i]+,en = pos[i+] - ; for (int j = st;j <= en;j++)
{
if (c.find(a[j]) == c.end())
{
c.insert(a[j]);
s.insert(j);
}
} ans = max((int)s.size(),ans);
} printf("%d\n",ans); return ;
}

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

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

    Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...

  2. Codeforces Round #436 (Div. 2) A,B,D

    A. Fair Game 题目链接:http://codeforces.com/contest/864/problem/A 水题 #include<iostream> #include&l ...

  3. Codeforces Round #436 (Div. 2) 题解864A 864B 864C 864D 864E 864F

    A. Fair Game time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集 bfs

    F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Pol ...

  5. Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心

    C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集

    题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes inp ...

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

    http://codeforces.com/contest/864/problem/C 题意: 坐标轴上有x = 0和 x = a两点,汽车从0到a之后掉头返回,从a到0之后又掉头驶向a...从0到a ...

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

    http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择 ...

  9. Codeforces Round #436 (Div. 2)

    http://codeforces.com/contest/864 第一次打cf的月赛-- A 题意:给你一个数列,问你能不能保证里面只有两种数且个数相等.2<=n<=100,1<= ...

随机推荐

  1. python趣味——与MS系列编译器一样强大的Unicode变量名支持

    中文变量名,中文函数名,中文类名等,可惜Python2不支持,但在Python3时代,这些都可以完美支持了. def 中文函数(): return 1

  2. Mysql使用规范文档 20180223版

    强制:不允许在跳板机上/生产服务器上手工连接,查询或更改线上数据 强制:所有上线脚本必须先在测试环境执行,验证通过以后方可在生产环境执行. 强制:上线脚本的编码格式统一为UTF-8 强制:访问数据库需 ...

  3. 1833 深坑 TLE 求解

    题目描述: 大家知道,给出正整数n,则1到n这n个数可以构成n!种排列,把这些排列按照从小到大的顺序(字典顺序)列出,如n=3时,列出1 2 3,1 3 2,2 1 3,2 3 1,3 1 2,3 2 ...

  4. reinterpret_cast,static_cast, dynamic_cast,const_cast的运用分析

    reinterpret_cast(重新解释类型转换) reinterpret_cast 最famous的特性就是什么都可以,转换任意的类型,包括C++所有通用类型,所以也最不安全 应用 整形和指针之间 ...

  5. Comparable接口和Comparator接口

    1.一个类在设计之初就要实现对该类对象的排序功能,那么这个类要实现Comparable接口,实现public int compareTo(T t)方法.如代码中的Student类.对于实现Compar ...

  6. C#添加背景音乐

    <MediaElement Name="audio"/> <Button Name="music" Content="点我有音乐哦& ...

  7. Spring Boot 2.0(六):使用 Docker 部署 Spring Boot 开源软件云收藏

    云收藏项目已经开源2年多了,作为当初刚开始学习 Spring Boot 的练手项目,使用了很多当时很新的技术,现在看来其实很多新技术是没有必要使用的,但做为学习案例来讲确实是一个绝佳的 Spring ...

  8. 随机四则运算的出题程序java

    一.设计思想 1.功能较多必须有菜单选择项,将一个大程序分为若干个功能模块的小程序,逐个实现2.针对题目避免重复时先将已生成的算式保存,然后将下一条生成的式子进行判断是否已生成,如果生成则返回循环语句 ...

  9. 20162323周楠《Java程序设计与数据结构》第八周总结

    20162323周楠 2016-2017-2 <程序设计与数据结构>第八周学习总结 教材学习内容总结 一个异常是一个对象,它定义了并不轻易出现的或是错误的情形 异常由程序或运行时环境抛出, ...

  10. MySQL 服务安装及命令使用

    MySQL 服务安装及命令使用 课程来源说明 本节实验后续至第17节实验为本课程的进阶篇,都基于 MySQL 官方参考手册制作,并根据实验楼环境进行测试调整改编.在此感谢 MySQL 的开发者,官方文 ...