codeforces 888C K-Dominant Character
来源:互联网 发布:select两张表所有数据 编辑:程序博客网 时间:2024/06/05 19:55
C. K-Dominant Character
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Input
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
Output
Print one number — the minimum value of k such that there exists at least one k-dominant character.
Examples
input
abacaba
output
2
input
zzzzz
output
1
input
abcde
output
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Input
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
Output
Print one number — the minimum value of k such that there exists at least one k-dominant character.
Examples
input
abacaba
output
2
input
zzzzz
output
1
input
abcde
output
3
题意:每个长度为k的子串都有一个相同的字符,求最小的k
思路:从a到z找一遍,找到最小的k值
#include<bits/stdc++.h>using namespace std;string s;int main(){ cin>>s; int ans=1e6; for(int i='a'; i<='z'; i++) { int k=0,t=0; for(int j=0; j<s.size(); j++) { if(s[j]==i) t=0; else t++; k=max(t,k); } ans=min(k,ans); } cout<<ans+1<<endl;}
阅读全文
0 0
- Codeforces 888C:K-Dominant Character
- codeforces 888C K-Dominant Character
- CodeForces 888C Dominant Character
- K-Dominant Character CodeForces
- K-Dominant Character CodeForces
- C. K-Dominant Character
- Educational Codeforces Round 32 C. K-Dominant Character(模拟)
- CodeForces 431C K-Tree
- CodeForces 431C k-Tree
- CodeForces 275C k-Multiple Free Set
- Codeforces Round247 C k-tree DP
- Codeforces #247 (Div. 2) C. k-Tree
- CodeForces 431C k-Tree(dp)
- codeforces-431C-k-Tree【dp】
- Codeforces 625C K-special Tables 【贪心】
- CodeForces 625C K-special Tables
- Codeforces 625C - K-special Tables
- CodeFOrces 625C - K-special Tables
- Linux用户管理
- java实现树形展示
- 谈PHP中信息加密技术
- weiphp2.0:关于OneThink后台添加密码重置的功能
- numpy中的ndarray与pandas的Series和DataFrame之间的相互转换
- codeforces 888C K-Dominant Character
- 树的应用之相同树的判断
- 自定义包及模块的导入
- Unity中物体添加刚体属性后,运行出现掉落情况如何解决?
- Dubbo 疯狂更新!阿里开源要搞大事情?
- shell脚本监控进程
- Linux基础命令(三)之top详解
- JAVA中获取文件MD5值的四种方法
- 稀疏矩阵的快速转置