[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 ...
随机推荐
- centos 增加网卡
CentOS 6添加网卡的方法 (2013-11-26 17:19:44) 转载▼ 标签: it 分类: Linux 前段时间安装了1台XEN server虚拟机,之前只用了1个网卡,ip是10.11 ...
- mvc, web mvc, spring web mvc 区别
1. MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用于组织代码用一种业务逻辑和数据显示分离的 ...
- Nginx总结.md
基本配置 注意:下面的nginx版本是1.10,安装是在CentOS 7中通过epel源进行安装的nginx默认配置文件. # egrep -v "(^$)|(^#)|#" /et ...
- [USACO09MAR]Cow Frisbee Team
嘟嘟嘟 这个是一个很明显的dp,遇到这种倍数的问题的,就令dp[i][j]表示选到了第 i 只牛(不是选了 i 只牛),sum(Ri) % f == j 的方案数,则, dp[i][j] = dp[i ...
- Day5 JavaScript(三)事件、表单验证以及初识jQuery
事件 1)鼠标事件 mousedown mouseup 2)键盘事件 a) keydown:键被按下 b) keyup:键抬起 c) keypress:按下可打印字符的键时. document.onk ...
- virtualbox+vagrant学习-2(command cli)-5-vagrant halt命令
Halt 格式: vagrant halt [options] [name|id] 该命令关闭vagrant管理的正在运行的机器. userdeMacBook-Pro:~ user$ vagrant ...
- App-IOS与Android弱网环境测试
弱网环境下App的功能是否正常使用,是否会发生Crash的等情况? 1.IOS ios系统一般自带弱网环境测试,可以通过设置各种网络环境,模拟弱网环境,如3G,wifi,very bad Networ ...
- js之checkbox判断常用示例
checkbox常用示例可参考: 关于checkbox自动选中 checkbox选中并通过ajax传数组到后台接收 MP实战系列(十三)之批量修改操作(前后台异步交互) 本次说的是,还是关于智能门锁开 ...
- layui弹出层之应用实例讲解
从酒店管理系统到智能门锁及其现在的资源共享平台,layui框架,我们团队用的比较多的就是这个layui弹出层. layui弹出层,除了页面iframe层我们比较常用还有就是表单校验和其他相关的友好提示 ...
- windows同时安装python2和python3
系统之前安装了python2.7,现在准备装个python3.6 1:首先下载一个python3.6适合windows32位的包python-3.6.5.exe 然后直接默认双击安装,安装的时候勾选a ...