zoukankan      html  css  js  c++  java
  • CodeForces-Zuhair and Strings(思维+枚举)

    Given a string ss of length nn and integer kk (1≤k≤n1≤k≤n). The string ss has a level xx, if xx is largest non-negative integer, such that it's possible to find in ss:

    • xx non-intersecting (non-overlapping) substrings of length kk,
    • all characters of these xx substrings are the same (i.e. each substring contains only one distinct character and this character is the same for all the substrings).

    A substring is a sequence of consecutive (adjacent) characters, it is defined by two integers ii and jj (1≤i≤j≤n1≤i≤j≤n), denoted as s[i…j]s[i…j] = "sisi+1…sjsisi+1…sj".

    For example, if k=2k=2, then:

    • the string "aabb" has level 11 (you can select substring "aa"),
    • the strings "zzzz" and "zzbzz" has level 22 (you can select two non-intersecting substrings "zz" in each of them),
    • the strings "abed" and "aca" have level 00 (you can't find at least one substring of the length k=2k=2 containing the only distinct character).

    Zuhair gave you the integer kk and the string ss of length nn. You need to find xx, the level of the string ss.

    Input

    The first line contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the length of the string and the value of kk.

    The second line contains the string ss of length nn consisting only of lowercase Latin letters.

    Output

    Print a single integer xx — the level of the string.

    Examples

    Input

    8 2
    aaacaabb
    

    Output

    2
    

    Input

    2 1
    ab
    

    Output

    1
    

    Input

    4 2
    abab
    

    Output

    0
    

    Note

    In the first example, we can select 22 non-intersecting substrings consisting of letter 'a': "(aa)ac(aa)bb", so the level is 22.

    In the second example, we can select either substring "a" or "b" to get the answer 11.

    思路:从'a'-'z'枚举即可

    代码:

    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    #include<iostream>
    
    using namespace std;
    char a[200005];
    
    int main()
    {
    	
    	int n,k;
    	cin>>n>>k;
    	getchar();
    	scanf("%s",a);
    	int len=strlen(a);
    	int maxn=0;
    	for(char  t='a';t<='z';t++)
    	{
    		
    		
    		int sum=0;
    		int ss=0;
    		for(int j=0;j<len;j++)
    		{
    			if(a[j]!=t)
    			{
    				sum+=ss/k;
    				ss=0;
    			}
    			else
    			{
    				ss++;
    			}
    		}
    		sum+=ss/k;
    		maxn=max(sum,maxn);
    	}
    	cout<<maxn<<endl;
    	
    	
    	return 0;
    }
  • 相关阅读:
    windows文件名非法字符过滤检测-正则表达式
    IEflash遇到flash遮挡
    打印iphone支持的所有字体
    xml字符串转xml对象,xml对象转json对象
    本地windows安装memcached服务
    resin启动时报错com.caucho.config.LineConfigException的解决
    8个Javascript小技巧,让你写的代码有腔调
    如何在MySQl数据库中给已有的数据表添加自增ID?
    mysql删除重复数据方法
    用Rem来无脑还原Web移动端自适应的页面
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781837.html
Copyright © 2011-2022 走看看