[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的网络编程 Socket编程
Socket是进程间通信的一种方式,与其他进程间通信的一个主要不同是:能实现不同主机间的进程间通信,网络上各种各样的服务大多都是基于Socket来完成通信的,要解决网络上两台主机间的通信问题,首先要唯 ...
- Hibernate三种状态;query查询;ResultTransformer转换为pojo对象;能够将query语句写在xml中;Criteria查询;ProjectionList总和/f分组等函数
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u010026901/article/details/24256091 Session操作过程中的po ...
- MySQL 导出远程服务器数据库 为 sql文件
MySQL 导出远程服务器sql文件 mysqldump -h192.168.1.111 –P3306 -uroot -ppassword --default-character-set=utf8 t ...
- 使用transient关键字解决ehcache序列化错误
使用Ehcache时发现个不起眼的小问题 在一个Model中有以下代码: public class MyModel implements Serializable { private static f ...
- BZOJ1188:[HNOI2007]分裂游戏(博弈论)
Description 聪聪和睿睿最近迷上了一款叫做分裂的游戏.该游戏的规则试:共有n个瓶子,标号为0,1,2.....n-1,第i个瓶子中装有p[i]颗巧克力豆,两个人轮流取豆子,每一轮每人选择3个 ...
- 2002. [HNOI2010]弹飞绵羊【LCT】
Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...
- P2245 星际导航
题目描述 sideman 做好了回到 Gliese星球的硬件准备,但是 sideman 的导航系统还没有完全设计好.为了方便起见,我们可以认为宇宙是一张有 N 个顶点和 M 条边的带权无向图,顶点表示 ...
- vux UI 项目国际化
第一步必须装 vux vux-loader vuex 和vuex-i18n npm i vux-loader -D npm i vuex vux vuex-i18n -S 安装完成需要配置webpac ...
- 时分秒倒计时的js实现
示例: 剩余天数:08天02事02分02秒 html代码: <div id="timer" data-timer="20160628140203" sty ...
- 域对象 request
一)域对象: 1)request的生命周期: 从请求开始创建,到响应完成结束. 2) 作用:携带一次请求内的数据. 3)请求转发: 请求转发: 1)浏览器发送请求到服务器A,然后服务器A将请求转发到 ...