Codeforces 888C:K-Dominant Character
来源:互联网 发布:高洛峰php免费视频 编辑:程序博客网 时间:2024/06/05 10:34
题目链接
K-Dominant Character
Problem Description
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
2input
zzzzz
output
1input
abcde
output
3
题意:
给出一个字母串,k满足:长度至少为k的字串一定包含某字母c,求最小的k
解题思路:
一个数组记录每个字母上一次出现的位置,用来计算另一个数组:记录每个字母与其相邻的相同字母的最大距离(设0和len两个位置一定有相同的字母),答案就是这个数组中的最小值啦~
Code:
#include <cstdio>#include <iostream>#include <cstring>#include <map>using namespace std;const int maxn=100000+5;char s[maxn];int last[50];int dis[50];int main(){ scanf("%s",s); memset(last,-1,sizeof(last)); int len=strlen(s); for(int i=0; i<len; i++) { int c=s[i]-'a'; dis[c]=max(dis[c],i-last[c]); last[c]=i; } for(int i=0; i<26; i++) dis[i]=max(dis[i],len-last[i]); int ans=len; for(int i=0; i<26; i++) { //cout<<dis[i]<<' '; ans=min(ans,dis[i]); } printf("%d\n",ans); return 0;}
阅读全文
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
- 妹控
- vs2017 编译最新的谷歌v8 6.4.0 版本 引擎
- CsvHelper, 帮助读取和写入CSV文件的库
- 现代软件工程_团队项目_阿尔法阶段_市场调研问卷_2017.11.11
- xmlview, 用于 Google Chrome 和Safari的强大的XML查看器
- Codeforces 888C:K-Dominant Character
- java中有些特殊的类不需要或不能创建实例对象!
- 偏偏喜欢你
- 多线程中断机制
- 深入理解操作系统(吓一下你)
- 控制Elasticsearch分片和副本的分配
- Java基础知识的概括
- jekyll-tagging, osm插件自动生成标签云和标签页面
- ssm框架,当某个框架的jar包升级版本后报错创建某个bean出错