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个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
随机推荐
- Vue中的计算属性和监听器(computed 与 watch)
react中数据是单向绑定的,而vue中数据是双向绑定的.为什么? 在react中,主要是通过setState 去改变state的值:而在vue中,会自动的触发set 与get 改变属性的值. 在vu ...
- Appium——解决每次启动时都安装setting和unlock app方法
找到appium安装目录 C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android 修改代码,注释掉弹出setting ...
- java版的下雪,大家圣诞快乐
1. [代码][Java]代码 package com.yk.tools.game; import java.applet.AudioClip;import java.awt.Dimension ...
- llala js弹出层 颜色渐变
网址:http://bbs.csdn.net/topics/370254842
- C和C++语言&
#include "stdafx.h"#include "iostream"#include "animal.h"using namespa ...
- ip策略路由
ip route 只是基于目的地址的路由选择 ip rule 路由策略,控制路由选择,可根据源地址,源IP等进行路由选择 路由策略由选择符合操作组成 ip rule add 添加策略 ip r ...
- ubuntu 常见问题解决
1.更新出现Could not get lock /var/lib/apt/lists/lock问题解决方法: 首先输入命令:sudo rm /var/lib/apt/lists/* -vf 执行完成 ...
- uiautomator2.0框架
1. Uiautomator1.0 Uiautomator2.0 date 2012 2015 super class UiAutomatorTestCase InstrumentationTes ...
- Linux 无法登陆172.***.***.***的子网
1. sudo dhclient -r 这条命令重复执行几次 2. dhclient - 3.查看ifconfig
- PLSQL ORA-12154 TNS无法解析指定的连接标识符
若你的机子上Windows 64位操作系统, 将PL Sql 的默认安装目录 Program Files (x86) 文件夹改为Program Files 或者别的便可以了