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.

Example

Input
abacaba
Output
2
Input
zzzzz
Output
1
Input
abcde
Output
3

自己用两重for循环写了一个代码,提交的时候TEL
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm> using namespace std; int main()
{
struct nood
{
char c;
bool b;
} a[]; char s[];
scanf("%s", &s);
int len = strlen(s);
for(int i = ; i < len; i++)
{
a[i].c = s[i];
a[i].b = true;
} int flag1 = ;
int flag2 = ;
int maxn = ;
int ans[]; for(int i = ; i < len; i++)
{
if(a[i].b == true)
{
for(int j = i+; j < len; j++)
{
if(a[i].c == a[j].c)
{
maxn = max(maxn ,j - i - flag2);
flag2 = j - i;
a[j].b = false;
}
}
}
ans[flag1++] = maxn;
} sort(ans, ans+flag1); bool judge = true;
for(int i = ; i < len; i++)
{
if(!a[i].b)
judge = false;
} if(judge)
printf("%d\n", len/ + );
else
printf("%d\n", ans[]); return ;
}

 AC代码

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; vector <int> T[];
vector <int> res[];
const int INF=0x3f3f3f3f; int main(){
int len,tmp,t,ans=INF;
string s;
cin>>s;
len=s.size();
for(int i=;i<;i++) T[i].push_back(-);//最前面的处理
for(int i=;i<len;i++){
tmp=s[i]-'a';
t=i-T[tmp].back();
T[tmp].push_back(i);
res[tmp].push_back(t);
}
for(int i=;i<;i++){
t=len-T[i].back();//最后面的处理
res[i].push_back(t);
sort(res[i].begin(),res[i].end());
}
for(int i=;i<;i++){
if(res[i].size()>){
ans=min(ans,res[i].back());
}
}
if(ans==INF) cout<<len/+<<endl;
else cout<<ans<<endl;
return ;
}

K-Dominant Character (模拟)的更多相关文章

  1. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem K. UTF-8 Decoder 模拟题

    Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c702 ...

  2. HDU 5122 K.Bro Sorting(模拟——思维题详解)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5122 Problem Description Matt's friend K.Bro is an A ...

  3. [Tyvj1001]第K极值 (贪心?模拟)

    考前打tyvj的水题 题目描述 给定一个长度为N(0<n<=10000)的序列,保证每一个序列中的数字a[i]是小于maxlongint的非负整数 ,编程要求求出整个序列中第k大的数字减去 ...

  4. Codeforces Round #754 (Div. 2) C. Dominant Character

    题目:Problem - C - Codeforces 如代码,一共有七种情况,注意不要漏掉  "accabba"  , "abbacca"  两种情况: 使用 ...

  5. Leetcode: Rearrange String k Distance Apart

    Given a non-empty string str and an integer k, rearrange the string such that the same characters ar ...

  6. Leetcode: Longest Substring with At Most K Distinct Characters && Summary: Window做法两种思路总结

    Given a string, find the length of the longest substring T that contains at most k distinct characte ...

  7. Longest Substring with At Most K Distinct Characters

    Given a string, find the longest substring that contains only two unique characters. For example, gi ...

  8. [python3.5][PyUserInput]模拟鼠标和键盘模拟

    一.PyUserInput安装 python3.5的PyMouse和PyKeyboard模块都集成到了PyUserInput模块中.在python3.5中,直接安装PyUserInput模块即可 Py ...

  9. 【2018暑假集训模拟一】Day1题解

    T1准确率 [题目描述] 你是一个骁勇善战.日刷百题的OIer. 今天你已经在你OJ 上提交了y 次,其中x次是正确的,这时,你的准确率是x/y.然而,你最喜欢一个在[0; 1] 中的有理数p/q(是 ...

  10. 机器学习方法(七):Kmeans聚类K值如何选,以及数据重抽样方法Bootstrapping

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入.我的博客写一些自己用得到东西,并分享给 ...

随机推荐

  1. 反射ORM 三层(for oracle)

    sql server and oracle 不同之处只在于: 1·参数@和: 2·自增和序列 3·oracle使用了存储过程以获得当前插入数据的ID DAL层的ORM using Oracle.Dat ...

  2. Java-API:un-java.util.Set

    ylbtech-Java-API:java.util.Set 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. https://docs.oracle.com ...

  3. Java8 日期和时间实用技巧

    新的日期API ZoneId: 时区ID,用来确定Instant和LocalDateTime互相转换的规则 Instant: 用来表示时间线上的一个点 LocalDate: 表示没有时区的日期, Lo ...

  4. 12-15winform--窗体

    一.窗体:有许多控件组成,空间本身就是类对象: 1)每一个控件都有自己的属性和方法. 2)控件的方法叫做事件: 3)同一命名空间下的项目文件是一个整体文件.设计器的代码(类文件)在“解决方案管理器”- ...

  5. 前端seo小结,网页代码优化

    seo的目的:提高网站流量 search engine optimization 搜索引擎优化seo search engine marketing 搜索引擎营销sem 权重10个等级 等级越大,权重 ...

  6. ListView显示Sqlite的数据

    在安卓中,ListView和Sqlite都是十分常用的.这次我们来结合这个两个知识点写一个Demo. 功能:吧SQLite中的数据用ListView显示出来. 先看截图吧 首先是数据库 然后是运行截图 ...

  7. Spring事务SPI及配置介绍

      Spring事务SPI及配置介绍 标签: spring事务aop数据管理 2015-05-17 11:42 606人阅读 评论(0) 收藏 举报  分类: Spring(12)  版权声明:本文为 ...

  8. 超详细的Maven使用教程

    原文:  http://blog.csdn.net/u010425776/article/details/52027706 主题 Maven 什么是Maven? 如今我们构建一个项目需要用到很多第三方 ...

  9. jstl 判断 null

    <c:if test="${not empty object }"> ${object}不为空 </c:if>

  10. 支撑矢量机SVM

    1.线性SVM 首先,回顾一下SVM问题的定义,如下: 线性约束很烦,不方便优化,是否有一种方法可以将线性约束放到优化问题本身,这样就可以无拘无束的优化,而不用考虑线性约束了.其对应的拉格朗日对偶形式 ...