Codeforces Round #436 (Div. 2) B. Polycarp and Letters
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的更多相关文章
- Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...
- Codeforces Round #436 (Div. 2) A,B,D
A. Fair Game 题目链接:http://codeforces.com/contest/864/problem/A 水题 #include<iostream> #include&l ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #436 (Div. 2) E. Fire
http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择 ...
- Codeforces Round #436 (Div. 2)
http://codeforces.com/contest/864 第一次打cf的月赛-- A 题意:给你一个数列,问你能不能保证里面只有两种数且个数相等.2<=n<=100,1<= ...
随机推荐
- python爬微信公众号前10篇历史文章(1)-思路概览
作为程序员,要时刻保持一颗好奇心和想要学习的姿态. 练习怎样利用搜狗微信爬取某指定微信公众号的历史文章.爬取微信公众号本身难度非常大,感谢搜狗提供了一个可以爬取数据的平台. 代码部分参考于: http ...
- server.xml 解析
server.xml的结构: 常用配置的参数注释: <?xml version='1.0' encoding='utf-8'?> <!-- Licensed to the Apach ...
- javascript中词法环境、领域、执行上下文以及作业详解
词法环境(Lexical Environments) 官方规范对词法环境的说明是:词法环境(Lexical Environments)是一种规范类型,用于根据ECMAScript代码的词法嵌套结构来定 ...
- 一、Android四大框架之ContentProvider的学习与运用,实现SQLite的增删改查。
本文系原创博客,文中不妥烦请指出,如需转载摘要请注明出处! ContentProvider的学习与运用 Alpha Dog 2016-04-13 10:27:06 首先,项目的地址:https:// ...
- 将 Shiro 作为应用的权限基础 一:shiro的整体架构
将 Shiro 作为应用的权限基础 一:shiro的整体架构 近来在做一个重量级的项目,其中权限.日志.报表.工作量由我负责,工作量还是蛮大的,不过想那么多干嘛,做就是了. 这段时间,接触的东西挺多, ...
- alpha冲刺第三天
一.合照 二.项目燃尽图 三.项目进展 今天是一个瓶颈期,在昨天被困住的地方今天还是没能解决,所以今天的项目进展并没有发生什么变化. 今天晚上xl和lj去实验室找学姐了,在学姐的帮助下大概有了一点思路 ...
- Beta No.4
今天遇到的困难: 百度位置假死的问题研究发现并不是源于代码的问题,而是直接运行在主线程中会出现诸多问题 Fragment碎片刷新时总产生的固定位置的问题未果 今天完成的任务: 陈甘霖:修复了部分Bug ...
- C语言博客作业--嵌套循环
一.PTA实验作业 题目1:7-4 换硬币 2 .设计思路 第一步:定义3个整型变量i,j,k用于循环,定义3个整型变量x,count,total分别用于储存零钱数额,换法个数,硬币数量: 第二步:输 ...
- Swift - 使用导航条和导航条控制器来进行页面切换并传递数据
转自:http://www.hangge.com/blog/cache/detail_586.html
- django搭建web (四) models.py
demo 该demo模型主要是用于问题,选择单个或多个答案的问卷形式应用 # -*- coding: utf-8 -*- from __future__ import unicode_literals ...