[Codeforces-888C] - K-Dominant Character
2 seconds
256 megabytes
standard input
standard output
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant character.
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
Print one number — the minimum value of k such that there exists at least one k-dominant character.
abacaba
2
zzzzz
1
abcde
3
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std; int main(){
string str;
while(cin>>str){
getchar();
// cout<<" len = "<<str.length()<<endl;
int ans = 1e6;
for(int i='a';i<='z';i++){
int k = , t = ;
for(int j=;j<str.length();j++){ if(str[j]==i)
t=;
else
t++;
k = max(k,t);
}
// cout<<" k = "<<k<<endl;
ans = min(k,ans);
}
cout<<ans<<endl;
}
}
[Codeforces-888C] - K-Dominant Character的更多相关文章
- Codeforces 888C: K-Dominant Character(水题)
		
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff ...
 - K-Dominant Character CodeForces - 888C
		
题目链接:https://vjudge.net/problem/CodeForces-888C 划一条线,使得不论怎么划线,都会出现一个特定的字符,那么这条线最短要多长. 用字符间隔考虑. 先判断哪些 ...
 - Codeforces Round #754 (Div. 2) C. Dominant Character
		
题目:Problem - C - Codeforces 如代码,一共有七种情况,注意不要漏掉 "accabba" , "abbacca" 两种情况: 使用 ...
 - Codeforces gym102152 K.Subarrays OR
		
传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...
 - Codeforces 101572 D - Distinctive Character
		
D - Distinctive Character 思路:bfs 使最大的匹配数最小,转换一下,就是使最小的不匹配数最大,用bfs找最大的距离 代码: #pragma GCC optimize(2) ...
 - codeforces 1133E  K Balanced Teams
		
题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...
 - Codeforces 1133E - K Balanced Teams - [DP]
		
题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不 ...
 - codeforces 1269E K Integers (二分+树状数组)
		
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...
 - codeforces 1282B2. K for the Price of One (Hard Version) (dp)
		
链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...
 - Codeforces 544E  K Balanced Teams (DP)
		
题目: You are a coach at your local university. There are nn students under your supervision, the prog ...
 
随机推荐
- JavaScript基础进阶之数组方法总结
			
数组常用方法总结: 下面我只总结了es3中常用的数组方法,一共有11个.es5中新增的9个数组方法,后续再单独总结. 1个连接数组的方法:concat() 2个数组转换为字符串的方法:join(). ...
 - python第十九课——random模块中的常用函数
			
1.random():返回一个[0,1)的随机浮点数(双精度浮点数) 2.uniform(a,b): 返回[a,b]之间的一个随机浮点数(双精度浮点数) [注意]a和b接受的数据大小随意 例如:3.r ...
 - HtmlImageGenerator字体乱码问题解决、html2image放linux上乱码问题解决
			
使用html2image-0.9.jar生成图片. 在本地window系统正常,放到服务器linux系统时候中文乱码问题.英文可以,中文乱码应该就是字体问题了. 一.首先需要在linux安装字体,si ...
 - crontab定时执行
			
一.crond简介 crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动cro ...
 - python获取网站http://www.weather.com.cn 城市 8-15天天气
			
参考一个前辈的代码,修改了一个案例开始学习beautifulsoup做爬虫获取天气信息,前辈获取的是7日内天气, 我看旁边还有8-15日就模仿修改了下.其实其他都没有变化,只变换了获取标签的部分.但是 ...
 - python 小技巧同时迭代多个列表,多变量同时运算
			
再来一个大家很熟悉的 dict={"a": "b","c": "d"}k,v=dict.items()print(k,v ...
 - MapReduce经典入门小案例
			
/** * 单词统计 * @author fengmingyue * */ public class WordCount { public static void main(String[] args ...
 - C++ - 类的虚函数\虚继承所占的空间
			
类的虚函数\虚继承所占的空间 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24236469 char占用一个字节, 但不满足4的 ...
 - 渲染引擎,HTML解析
			
这是how browser to work 的翻译 转自:携程设计委员会 渲染引擎 渲染引擎的职责是……渲染,也就是把请求的内容显示到浏览器屏幕上. 默认情况下渲染引擎可以显示HTML,XML文档以及 ...
 - 洛谷P3382 【模板】三分法(三分)
			
题目描述 如题,给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减.试求出x的值. 输入输出格式 输入格式: 第一行一次包含一个正整数N和两个实数l.r,含 ...