Codeforces round #193 (Div. 2) a Down the hatch!

Source: Internet
Author: User

/*

Well, this competition started at. At that time, Meng Shen and I were watching the second season of the prison. At the end of the competition, I lay down and prepared to go to bed. I saw Tao shenfa say I couldn't understand question a, And then I checked it on my mobile phone. cf

Question A is easy to understand. Then I talked to Yan Wu about my thoughts. He said that he was very close to the great god. Well, he went to bed.

Then I got up and spent two minutes coding the code. After I handed it in, I got the AC. Happy ~

*/

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. AllNPeople
Who came to the barbecue sat in a circle (thus each person has ed a unique indexBIFrom
0NCounter-increment 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. IfJ-Th
Turn was made by the person with indexBI,
Then this person acted like that:

  1. He pointed at the person with index (BILimit + limit 1)Mod nEither
    With an elbow or with a nod (X mod yIs the remainder after dividingXByY);
  2. IfJLatency ≥ 4 and the players who had turns numberJExecutor-cores 1,JAccept-limit 2,JExecutor-cores 3,
    Made during their turns the same moves as playerBIOn
    The current turn, then he had drunk a glass of juice;
  3. The turn went to Person Number (BILimit + limit 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 cocould 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 integerN(4 cores ≤ CoresNLimit ≤00002000)
-The number of participants in the game. The second line describes the actual game:I-Th character of this line equals 'A ',
If the participant ant who movedI-Th pointed at the next person with his elbow, and 'B ',
If the participant ant 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 cocould have drunk if he had played optimally well.

Sample test (s) Input
4abbba
Output
1
Input
4abbab
Output
0
Note

In both samples Vasya has got two turns-1 and 5. in the first sample, Vasya cocould have drunk a glass of juice during the previous th turn if he had pointed at the next person with a nod. in this case, the sequence of moves wowould look like "abbbb ". in the second
Sample Vasya wouldn't drink a single glass of juice as the moves stored med during turns 3 and 4 are different.

Let's briefly describe the meaning of the question. Vasya and his friends have a total of N people playing games in a circle. His number is 0. turn1.

It's your turn to take actions to point you next person (Bi + 1) mod
If n is used, exactly one circle of people in a loop (0, 1, 2... n-1, N, 2...) Will the elbow (A) or nod (B) be taken)

Then you act as a point, and drink can be used in the same way as those of the first three.
A glass of juice.

Because Vasya is disconnected, it can change the actions of the next person at his point. Other people will not change, so that you can find the maximum juice number to be able to drink.

Solution:

 
It's easy. From the second Vasya operation, if the first three of them acted the same way, they could have a drink.

Code:

# include<stdio.h># include<string.h>const int MAXN = 2000;char s[MAXN+10];int main(void){int n, i, count=0;scanf("%d", &n);scanf("%s", s);    for(i=0; i<strlen(s); i+=n){  if(i==0)  continue;  else  {    if(s[i-1]==s[i-2]&&s[i-1]==s[i-3])    count++;  }}    printf("%d\n", count);  return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.