[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 ...
随机推荐
- 1055. [HAOI2008]玩具取名【区间DP】
Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后 他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替, ...
- 全局唯一Id:雪花算法
雪花算法-snowflake 分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的. 有 ...
- Zookeeper学习之路 (二)集群搭建
ZooKeeper 软件安装须知 鉴于 ZooKeeper 本身的特点,服务器集群的节点数推荐设置为奇数台.我这里我规划为三台, 为别为 hadoop1,hadoop2,hadoop3 ZooKeep ...
- Apache去掉index.php
把 #LoadModule rewrite_module modules/mod_rewrite.so 前面的#去掉, 再把权限AllowOverride None都改为AllowOverride A ...
- Sequelize-nodejs-4-Model usage
Model usage模型使用 Data retrieval / Finders Finder methods are intended to query data from the database ...
- ubuntu16.04常见的问题解决方案
问题一:关于咖啡主机和其他服务器厂商和个人虚拟机VM10安装ubuntu16.04 ubuntu16.04默认是没有root用户的,要想有必须要通过用户创建,通常安装ubuntu16.04会有个让你创 ...
- find 的一些用法
find的一些用法 例1:find . -type f -exec chmod -R 644 {} \ ; #{}代表签名的输出,\;代表结束命令操作结束 例2: find -print0 |xa ...
- DOM几个重要的函数
最近在读js编程艺术,发现几个不错的函数,总结如下: 1.页面初始化加载函数onload 操作DOM的函数应该在页面元素初始化结束之后再立即执行,否则页面元素还没有初始化完成,DOM操作就会搁浅了:网 ...
- STM32F103 ucLinux开发BOOT
STM32F103 ucLinux开发BOOT STM3210E-EVAL官方开发板主芯片STM32F103ZET6: 片内512K Flash,地址0x0800 0000 ~ 0x0807 FFFF ...
- 【vue】vue项目引入 Element-UI
根据vue项目的搭建教程,接下来记录下如何在Vue-cli创建的项目中引入Element-UI. 1.安装直接用命令 (推荐) npm install element-ui 2.直接在根目录下的pac ...