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. Mecanim之IK动画

    序言:IK动画全名是Inverse Kinematics 意思是逆向动力学,就是子骨骼节点带动父骨骼节点运动. 比如体操运动员,只靠手来带动身体各个部位的移动.手就是子骨骼,身体就是它的父骨骼,这时运 ...

  2. C++实现Date日期类

    定义一个Date类,包含三个属性年.月.日 实现了如下功能: 年月日的增加.减少:2017年10月1日加上100个月30天是2025年5月31日 输出某天是星期几:2017年10月1日是星期日 判断某 ...

  3. poj-1503-java大数相加

    Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his explo ...

  4. Oracle/Hive/Impala SQL比较1

    5 Function      指数据库内置的function,不讨论UDF.另外,操作符都不比较了,区别不大.   5.1 数学函数 功能 Oracle Hive Impala ABS 绝对值,有 ...

  5. Konckout第五个实例:各种事件绑定

    点击加一: <!doctype html> <html > <head> <meta http-equiv="Content-Type" ...

  6. 由浅入深理解----java反射技术

    java反射机制详解 java反射机制是在运行状态下,对任意一个类可以获取该类的属性和方法,对任意一个对象可以调用其属性和方法.这种动态的获取信息和调用对象的方法的功能称为java的反射机制 clas ...

  7. android scrollview 属性

     理论部分1.ScrollView和HorizontalScrollView是为控件或者布局添加滚动条2.上述两个控件只能有一个孩子,但是它并不是传统意义上的容器3.上述两个控件可以互相嵌套4.滚动条 ...

  8. Hibernate学习笔记三 多表

    一对多|多对一 表中的表达 实体中的表达 实体代码: package com.yyb.domain; import java.util.HashSet; import java.util.Set; p ...

  9. Struts2学习笔记二 配置详解

    Struts2执行流程 1.简单执行流程,如下所示: 在浏览器输入请求地址,首先会被过滤器处理,然后查找主配置文件,然后根据地址栏中输入的/hello去每个package中查找为/hello的name ...

  10. 【Spring源码深度解析学习系列】容器的基础XmlBeanFactory(二)

    一.配置文件封装 Spring的配置文件读取是通过ClassPathResource进行封装的,如new ClassPathResource("test.xml"),那么Class ...