链接:https://codeforces.com/contest/1105/problem/B

题意:

给一个字符串和k,连续k个相同的字符,可使等级x加1,

例:8 2 aaacaabb

则有aa aa 即x=2。

求最大的k

思路:

第一眼想的是诶个查找,但是绝对会T,就没做,过一个小时才想到可以直接遍历,记录每个字符对应的最大x即可。

代码:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000+10;
char s[MAXN];
int vis[26]; int main()
{
int n,k;
scanf("%d%d",&n,&k);
scanf("%s",s+1);
int now = 0;
for (int i = 1;i<=n;i++)
{
if (s[i] == s[i-1] || i == 1)
{
now++;
if (now == k)
{
vis[s[i] - 97]++;
now = 0;
} }
else
{
now = 1;
if (now == k)
{
vis[s[i] - 97]++;
now = 0;
}
}
}
int sum = 0;
for (int i = 0;i<26;i++)
sum = max(sum,vis[i]);
cout << sum << endl; return 0;
}

  

Codeforces Round #533(Div. 2) B.Zuhair and Strings的更多相关文章

  1. Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模拟】

    传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...

  2. Codeforces Round #533 (Div. 2) B. Zuhair and Strings(字符串)

    #include <bits/stdc++.h> using namespace std; int main() { int n,k;cin>>n>>k; stri ...

  3. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  4. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  5. Codeforces Round #533 (Div. 2) Solution

    A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...

  6. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  7. Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】

    传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...

  8. Codeforces Round #533(Div. 2) C.Ayoub and Lost Array

    链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...

  9. Codeforces Round #533(Div. 2) D.Kilani and the Game

    链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...

随机推荐

  1. Sqoop hive导出到mysql[转]

    通过Sqoop将Hive表数据导入到MySQL通常有两种情况. 第一种是将hive上某张表的全部数据导入到mysql对应的表中. 第二种是将hive上某张表中的部分数据导入到mysql对应的表中. 两 ...

  2. android studio导入项目出现的奇葩错误

    1.Error:(1, 0) Cause: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0

  3. include vector 编译出错VC++

    error C2665: “operator new” : 5个重载中没有一个可以转换参数1(从“const char [71]”类型)这个错误是怎么回事啊,搜索了整个项目好像没有可疑的new操作阿. ...

  4. oracle查看锁表进程,杀掉锁表进程

    查看锁表进程SQL语句1: select sess.sid,     sess.serial#,     lo.oracle_username,     lo.os_user_name,     ao ...

  5. MFC中显示一张位图

    1.用类CBitmap加载位图 2.创建内存DC, 将位图选进此内存DC 3.调用BitBlt将内存DC的内容拷贝到其它DC(通知是显示DC) 例子(来自MSDN): // This OnDraw() ...

  6. Java笔记(七)

    File类: import java.io.File; import java.io.IOException; public class Demo{ public static void main(S ...

  7. SVN 如何更换IP地址

    一.进去项目空白处. 二.点击右键TortoiseSVN. 三.选中Relocate. 四.弹出框如下: 把原来的IP地址更换成新的IP地址,再点击OK就可以了.

  8. bzoj 3309 DZY Loves Math——反演+线性筛

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 像这种数据范围,一般是线性预处理,每个询问 sqrt (数论分块)做. 先反演一番.然 ...

  9. 从MySQL获取数据

    安装 PM> install-package newtonsoft.json PM> install-package mysql.data string connectionString ...

  10. ElasticSearch入门及核心概念介绍

      Elasticsearch研究有一段时间了,现特将Elasticsearch相关核心知识和原理以初学者的角度记录下来,如有不当,烦请指正! 0. 带着问题上路——ES是如何产生的? (1)思考:大 ...