Codeforces 1105B:Zuhair and Strings(字符串水题)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output
Given a string sss of length nnn and integer k (1≤k≤n)k\ (1≤k≤n)k (1≤k≤n). The string sss has a level xxx, if xxx is largest non-negative integer, such that it’s possible to find in sss:
- xxx non-intersecting (non-overlapping) substrings of length kkk,
- all characters of these x 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 iii and j (1≤i≤j≤n)j\ (1≤i≤j≤n)j (1≤i≤j≤n), denoted as s[i…j]s[i…j]s[i…j] = “sisi+1…sjs_is_{i+1}…s_jsisi+1…sj”.
For example, if k=2k=2k=2, then:
the string “aabb” has level 111 (you can select substring “aa”),
the strings “zzzz” and “zzbzz” has level 222 (you can select two non-intersecting substrings “zz” in each of them),
the strings “abed” and “aca” have level 000 (you can’t find at least one substring of the length k=2k=2k=2 containing the only distinct character).
Zuhair gave you the integer kkk and the string s of length nnn. You need to find xxx, the level of the string sss.
Input
The first line contains two integers nnn and k (1≤k≤n≤2⋅105)k\ (1≤k≤n≤2⋅10^5)k (1≤k≤n≤2⋅105) — the length of the string and the value of kkk.
The second line contains the string sss of length n consisting only of lowercase Latin letters.
Output
Print a single integer xxx — 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 222 non-intersecting substrings consisting of letter ‘a’: “(aa)ac(aa)bb”, so the level is 222.
In the second example, we can select either substring “a” or “b” to get the answer 111.
题意
给出一个长度为nnn的字符串,在字符串中查找连续出现kkk次的字母,中间不能有重叠,连续出现kkk次的字母最多出现了几次
AC代码
暴力查找即可,注意k=1k=1k=1的情况
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#include <time.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
#define bug cout<<"-------------"<<endl
#define debug(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<"\n"
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
char ch[maxn];
int a[maxn];
bool cmp(int a,int b)
{
return a>b;
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
cin>>ch;
int res=1;
for(int i=0;i<n;i++)
{
if(k==1)
a[ch[i]-'a']++;
else
{
if(ch[i]==ch[i+1])
res++;
else
res=1;
if(res==k)
{
a[ch[i]-'a']++;
res=1;
i+=1;
}
}
}
sort(a,a+26,cmp);
cout<<a[0]<<endl;
return 0;
}
Codeforces 1105B:Zuhair and Strings(字符串水题)的更多相关文章
- 1222: FJ的字符串 [水题]
1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = ...
- 1001 字符串“水”题(二进制,map,哈希)
1001: 字符串“水”题 时间限制: 1 Sec 内存限制: 128 MB提交: 210 解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
随机推荐
- Problem - 1062 http://acm.hdu.edu.cn/showproblem.php?pid=1062
对输入字符串的字符的倒置,在这个程序中,我觉得自己最大的问题是怎么识别一个字符,代码中有t个字符串,每个字符串,每个字符串中有若干个单词,单词之间有空格,所以对于下列的正确答案,我的疑惑是当我键盘输入 ...
- 重命名文件夹提示"找不到指定文件"
本人Win10使用360粉碎了一个文件夹后,出现如下问题,并且重启无效,因已修复好,借图: 出现以上问题不用慌,程序员必备技能,重装系统可破. 哈哈,开个玩笑,解决方法步骤如下: ①百度下载 Fold ...
- HFun.快速开发平台(二)=》自定义列表实例
应用系统中数据列表的展现是开发内容之一,实现的方式基本是通过编号具体的访问列表页实现,通过检索条件进行数据源的获取,列字段的描述,还可能会有检索条件的实现,列表数据的导出等功能. 为了将重复工作进行简 ...
- Python 的第一个小程序
F盘 新建文本文档 hello.txt 内容为: print("hello world! hello 2018!"); 打开CMD cd c:\ ...
- Vue移动端项目总结
使用Vue项目写了一个移动端项目,然后又把项目硬生生的抽离了组件,一直忙着写RN项目没有时间总结心得,今天上午终于下定决心,写点总结. 1.position:absolute: 定位的时候不同手机的浏 ...
- Python学习第四天
一.数字 int 二.字符串 str #以下均为补充内容 #对于空字符串是假 #数字0是假 #数字和字符串可以相互转换 # a="123" # b=int(a) # a=123 # ...
- 阶段01Java基础day26反射
27.01_反射(类的加载概述和加载时机) A:类的加载概述 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载,连接,初始化三步来实现对这个类进行初始化. 加载 就是指将class文 ...
- DD常用命令组合
管理一个系统经常需要备份磁盘数据,那么在UNIX/Linux系统中如何备份整个分区或整个硬盘的数据呢? dd命令就可以很方便实现这个功能. 1.把一个分区复制到一个文件中 dd if=/dev/sda ...
- lvs用户空间命令ipvsadm
ipvs工作在内核空间,而ipvsadm工作在用户空间,是负责管理集群服务编写规则的命令行工具 ipvsadm需要手动安装. $ yum -y install ipvsadm ipvsadm管理命令 ...
- 解决linux root 认证失败的问题
https://jingyan.baidu.com/article/3052f5a1f1b17c97f31f8688.html