[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 ...
随机推荐
- [错误记录]python requests库 Response 判断坑
在requests访问之后, 我直接判断resp的值, 如下: if resp: do something 发现当Response 为500的时候没有进入if分支, 检查源码,发现Response重写 ...
- c++ thread 使用不当导致的崩溃问题
看个例子 class CTimer{ public: // 析构函数 virtual ~CTimer(){ } // 开始 void start() { b_exit = false; i = ; t ...
- debian安装及使用mysql
在Debian中安装MySQL服务器是很方便的,使用apt-get命令即可完成. debian:~# apt-get install mysql-server mysql-client mysql-s ...
- FreeMaker常用方法
FreeMaker常用方法 1.表达式转换类 ${expression}计算expression并输出 #{ expression }数字计算#{ expression ;format}安格式输出数字 ...
- 如何使用正则做文本数据的清洗(附免费AI视频福利)
手工打造文本数据清洗工具 作者 白宁超 2019年4月30日09:43:59 前言:数据清理指删除.更正错误.不完整.格式有误或多余的数据.数据清理不仅仅更正错误,同样加强来自各个单独信息系统不同数据 ...
- attr全选第三次失效
一功能checkbox时隐时现,比如第一次打开有勾选,第n次打开可能就不选了. 经过偶层层抽次剥茧(da da jiang you),终于知道了原因:attr()在二次选中勾选框时,失效. 比如,如下 ...
- 多线程之CountDownLatch、CyclicBarrier和Semaphore
Java并发编程:CountDownLatch.CyclicBarrier和Semaphore 在java 1.5中,提供了一些非常有用的辅助类来帮助我们进行并发编程,比如CountDownLatch ...
- java 学习 命令行运行java程序
之前学习python,由于公司需要.现在不得已转java. 1.命令运行java程序. 程序名字:input.java code: /** * Created by liumeide on 2017/ ...
- Manifest XML signature is not valid(安装ClickOnce签名未通过验证)
转载:http://stackoverflow.com/questions/12826798/manifest-xml-signature-is-not-valid 安装时,我的问题: PLATFO ...
- 从公司服务器C盘被删说起
事情起因 一个阳(严)光(重)明(雾)媚(霾)的周二,对于我们从周二到周六的班次来说,这是新的一周开始.我像往常一样,打开电脑,倒上一杯水,开始翻阅从大洋彼岸发来的各种邮件.突然看到一封紧急的邮件,内 ...