Codeforces Problem 332A
来源:互联网 发布:java tcp服务器框架 编辑:程序博客网 时间:2024/06/04 18:30
Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!
Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All n people who came to the barbecue sat in a circle (thus each person received a unique index bi from 0 to n - 1). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the j-th turn was made by the person with index bi, then this person acted like that:
- he pointed at the person with index (bi + 1) mod n either with an elbow or with a nod (x mod y is the remainder after dividing x by y);
- if j ≥ 4 and the players who had turns number j - 1, j - 2, j - 3, made during their turns the same moves as player bi on the current turn, then he had drunk a glass of juice;
- the turn went to person number (bi + 1) mod n.
The person who was pointed on the last turn did not make any actions.
The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him.
You can assume that in any scenario, there is enough juice for everybody.
The first line contains a single integer n (4 ≤ n ≤ 2000) — the number of participants in the game. The second line describes the actual game: the i-th character of this line equals 'a', if the participant who moved i-th pointed at the next person with his elbow, and 'b', if the participant pointed with a nod. The game continued for at least 1 and at most 2000 turns.
Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well.
4abbba
1
4abbab
0
In both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the moves performed during turns 3 and 4 are different.
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;int main(){ int n,ans = 0; char s[2020]; scanf("%d%s",&n,s); for(int i=n;i<=strlen(s)-1;i+=n) if(s[i-1]==s[i-2]&&s[i-2]==s[i-3]) ans++; printf("%d\n",ans); return 0;}
- Codeforces Problem 332A
- Problem - 152A - Codeforces
- codeforces problem/244/A
- codeforces problem/415/A
- codeforces. problem/408/A
- Codeforces Problem 333A
- codeforces problem/416/A 二分
- codeforces 17A Noldbach problem
- 【codeforces 29A】Spit Problem
- CodeForces - 29A - Spit Problem
- CodeForces-17A-Noldbach problem
- 【codeforces 749A】Bachgold Problem
- Codeforces 749A-Bachgold Problem
- Problem--1A--Codeforces--TheatreSquare
- Problem--4A--Codeforces--Watermelon
- Problem--231A--Codeforces--Team
- Problem--282A--Codeforces--BIt++
- Problem--96A--Codeforces--Football
- String.indexOf源码分析
- 第二章 SQL命令参考-CREATE VIEW
- Python对文件和目录的操作
- Image Gradients
- Python opencv 中文路径乱码解决方法
- Codeforces Problem 332A
- Ubuntu17.04查看本机IP
- 《DOS命令一日通》第一章 引论,DOS概述
- Hive修改表
- 批量梯度下降(BGD)、随机梯度下降(SGD)、小批量随机梯度下降(MSGD)
- Jetty在win10上的配置,IDEA中配置Jetty,Maven中配置Jetty插件,Eclipse中配置Jetty插件及其使用,通过java代码内嵌Jetty Server
- 【大数据】开发环境搭建(一):Linux安装以及配置环境Nat
- 面试时必须理解的spring要点
- 《多核程序设计》学习笔记:蒙特卡洛法串行与并行求解π值