Codeforces Round #533(Div. 2) B.Zuhair and Strings
链接: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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
- Codeforces Round #533 (Div. 2) Solution
A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- 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 ...
- Codeforces Round #533(Div. 2) C.Ayoub and Lost Array
链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...
- Codeforces Round #533(Div. 2) D.Kilani and the Game
链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
随机推荐
- 人生苦短之Python发邮件
#coding=utf-8 import smtplib from email.mime.base import MIMEBase from email.mime.image import MIMEI ...
- Kotlin静态方法
Kotlin静态方法 工具类 全都是静态方法的情况 : class 类名 改为 object 类名 即可 package redwolf.com.moreimageupload import okht ...
- ZIP伪加密(deprecated)
ZIP伪加密 经过伪加密的apk,改成zip格式打开会发现里面的文件都经过了加密. APK实际上是Zip压缩文件,但是Android系统在解析APK文件时,和传统的解压压缩软件在解析Zip文件时存在差 ...
- nginx: error while loading shared libraries: libGeoIP.so.1
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz wget http://geolite.maxmind.com/do ...
- python 基础之第十三天(xineted服务器,forking,多线程)
- c++之cin/cin.get/cin.getline()详解
C++输入过程中,是把输入加载到缓冲区中,然后对缓冲区中的字符进行读取.cin,cin,get(),cin.getline()三个函数虽然都能进行数据读取,但是它们对缓冲区内数据的处理方法是不同的(如 ...
- RTP Payload Format for Transport of MPEG-4 Elementary Streams over http
1.SDP (1)Http Request GET /getSdpForUrl?HttpUrl=nphMpeg4/g726-640x480 HTTP/1.0/r/n Host: 58.63.71.90 ...
- spark运行模式之一:Spark的local模式安装部署
Spark运行模式 Spark 有很多种模式,最简单就是单机本地模式,还有单机伪分布式模式,复杂的则运行在集群中,目前能很好的运行在 Yarn和 Mesos 中,当然 Spark 还有自带的 Stan ...
- PHP参数类型
class User{ public $name; public $password; function __construct($name,$password){ ...
- 关于git被误删除的分支还原问题
在开发过程中, 有可能会将正在开发的本地分支误删, 本地分支被删除时, 如果已经将本地分支的变更推送到了远端, 还没有问题, 如果被删除的本地分支只提交了没有推送到远端, 就悲剧了, 相当于在你上一次 ...