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<= ...
随机推荐
- 一名Java架构师分享自己的从业心得,从码农到架构师我用了八年
工作了挺久,发现有个挺有意思的现象,从程序员.高级程序员,到现在挂着架构师.专家之类的头衔,伴随着技术和能力的提高,想不明白的事情反而越来越多了. 这些疑问有些来自于跟小伙伴的交流,有些是我的自问自答 ...
- SpringMVC的工作流程以及组件说明
1. SpringMVC处理流程 2. SpringMVC架构 2.1 框架结构 2.2 框架流程 1. 用户发送请求至前端控制器DispatcherServlet. 2. DispatcherSer ...
- vs调试正确显示utf8格式字符串
自从将visual studio从2010升级到2015后,发现调用接口的utf8格式字符串不能正常显示了,常常被莫名其妙截断,查了下,原来可以直接将变量拖到watch窗口中,在变量名后面手动添加,s ...
- thinkphp5 taglib自定义标签教程
学着写了一下,终于搞定了,顺便分享一下!taglib是tp框架自定义标签功能,如果你用过cms,肯定见过类似: {dede:arclist typeid='' row='' col='' titlel ...
- SpringBoot集成redis的key,value序列化的相关问题
使用的是maven工程 springBoot集成redis默认使用的是注解,在官方文档中只需要2步; 1.在pom文件中引入即可 <dependency> <groupId>o ...
- 替换Java字符串中的“& lt;”为“<”
发布webservice时 Java中的String类型会将 “<” 自动转换为 “<”,在建String转换为XML时就会出错,具体做法是: String strXml = “< ...
- 数据库中插入数据时发生ora-00984错误
操作Oracle数据库,插入数据时显示:ORA-00984列在此处不允许错误,如下图所示: 出现的原因是由于,在插入字符或字符串型字段时.如果插入的数据是纯数字,则不会有错误:如果出现字符,则会报OR ...
- 客户端(winform)更新
winform更新有两种情况,一种是在线更新在线使用:直接右击项目发布出去就可以更新在线使用了.还有一种更新是不用一直连接网络的模式. 1:C#Winform程序如何发布并自动升级--------ht ...
- HDFS之HA机制
- nyoj 过河问题
过河问题 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描述 在漆黑的夜里,N位旅行者来到了一座狭窄而且没有护栏的桥边.如果不借助手电筒的话,大家是无论如何也不敢过桥去的 ...