cf 193 div2 A. Down the Hatch!

A. Down the Hatch!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

  1. 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 byy);
  2. if j ≥ 4 and the players who had turns number j - 1j - 2j - 3, made during their turns the same moves as player bi on the current turn, then he had drunk a glass of juice;
  3. 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.

Input

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.

Output

Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well.

Sample test(s)
input
4
abbba
output
1
input
4
abbab
output
0
真心表示英语是个渣渣,又没看懂题意,在小健健大神的帮助下,最后算是弄清了,就是玩游戏 ,第一个人是起始点,每次回到他自己的时候,看他前面的3个人的动作是不是一样的,如果一样的话,就和一杯饮料,算总共要喝几杯。
下面是代码:
 
   
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

char str[2005];
int main(){
    int n;
while(scanf("%d",&n)!=EOF){
    cin>>str;
    int ans=0;
    int l=strlen(str);
    for(int i=0;i<l;i++){
         if(i%n!=0&&i!=0)
         continue;
         if(i<4)
         continue;
         if(str[i-1]==str[i-2]&&str[i-2]==str[i-3]&&str[i-1]==str[i-3])
             ans++;
    }
      cout<<ans<<endl;
  }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值