1) Link to the problem: http://codeforces.com/contest/888/problem/C

2) Description:

You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant if each substring of s with length at least contains this character c.

You have to find minimum k such that there exists at least one k-dominant character.

Input

The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).

Output

Print one number — the minimum value of k such that there exists at least one k-dominant character.

3) 思路:

这题的tag居然是binary search,我做的时候基本没往这方面想。

我的思路就是算每个字母的maxgap然后求最小。

数据长度最长是10^5,然后26个字母注意:大小写要区分。

最后大概是O(n)左右,time limit是2s。所以肯定能过。O(n^2)的话就不用想了,O(n^2)属于不理智行为。

4) Code:

#include <iostream>
#include <cstring>
using namespace std;
int main(){
string s;
cin>>s;
int n = s.size();
int min = INT_MAX; for(int i = ; i < ; i++)
{
char c;
if(i<)
c = (char)('a' + i);
else
c = (char)('A' + i - ); int count = ;
int maxgap = ;
for(int j = ; j < n; j++){
if(s[j] == c)
{
if(maxgap < count)
maxgap = count;
count = ;
}
else {
count ++;
}
}
if(maxgap < count)
maxgap = count;
if(maxgap < min)
min = maxgap;
if(min==)
break;
}
cout << min + ;
return ;
}

Educational Codeforces Round 32 Problem 888C - K-Dominant Character的更多相关文章

  1. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

  2. Educational Codeforces Round 21 Problem A - C

    Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...

  3. Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心

    After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...

  4. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  5. Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

  6. Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)

    You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist ...

  7. Educational Codeforces Round 32 Almost Identity Permutations CodeForces - 888D (组合数学)

    A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in thi ...

  8. Educational Codeforces Round 32 E. Maximum Subsequence

    题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...

  9. Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)

    题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...

随机推荐

  1. Codeforces Round #483 (Div. 2)C题

    C. Finite or not? time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. iOS 11.2 - 11.3.1 越狱教程

    iOS 11.2 - 11.3.1 越狱教程 一.准备相应的工具 (1) 下载 CydiaImpactor,官网地址是 http://cydiaImpactor.com (2) 下载 Electra, ...

  3. Redis(八):Redis的复制(Master/Slave)

    Redis的复制(Master/Slave)目录导航: 是什么 能干嘛 怎么玩 复制原理 哨兵模式(sentinel) 复制的缺点 是什么 官网 行话:也就是我们所说的主从复制,主机数据更新后根据配置 ...

  4. eclipse 安装 lombok

    转载自http://bbs.itmayiedu.com/article/1527769518449 由于项目中有 @Slf4j 注解等,而 eclipse 需要安装 lombok 插件才能正常编译.由 ...

  5. thinkphp5.0上对redis的具体操作

    一.环境搭建 首先先安装composer.thinkphp5.0版本.和redis的windows版本的redis程序或者linux版本的redis程序,linux安装教程: https://www. ...

  6. fiddler请求报文的headers属性详解

    fiddler请求报文的headers属性详解 headers的属性包含以下几部分. (1)Cache头域 在Cache头域中,通常会出现以下属性. 1. Cache-Control 用来指定Resp ...

  7. 浅谈ConcurrentHashMap实现原理

    我们都知道HashTable是线程安全的类,因为使用了Synchronized来锁整张Hash表来实现线程安全,让线程独占: ConcurrentHashMap的锁分离技术就是用多个锁来控制对Hash ...

  8. c语言数据结构(一)

    第一章   绪论 一.数据与数据结构 数据:所有能被输入到计算机中,且被计算机处理的符号的集合计算机操作的对象的总称.是计算机处理的信息的某种特定的符号表示形式. 数据元素:数据中的一个“个体”,数据 ...

  9. NSNull Crash处理 (NullSafe 的原理)

    问题场景 后端返回的数据中总会出现一些NSNull类型,当我们一处理程序就会崩溃,因此想到把返回的数据中的NSNull类型全部转换成@""空字符串 (1)原始的json串:后端返回 ...

  10. 开胃小菜——impress.js代码详解

    README 友情提醒,下面有大量代码,由于网页上代码显示都是同一个颜色,所以推荐大家复制到自己的代码编辑器中看. 今天闲来无事,研究了一番impress.js的源码.由于之前研究过jQuery,看i ...