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:

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);
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.

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
Note
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.

题意:

        给你n个人,开始报a或者b,第一个人开始然后轮流报数,如果你前面三个人连续报的是一样的字母就喝一杯酒。问你第一个人喝几杯酒?

代码:

      

 
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int n;
  5. string s;
  6. cin>>n;
  7. cin>>s;
  8. int cnt= 0;
  9. for(int i=n;i<s.length();i+=n){
  10. if(s[i- 1]==s[i- 2]&&s[i- 2]==s[i- 3])
  11. cnt++;
  12. }
  13. cout<<cnt<<endl;
  14. return 0;
  15. }

 

全部评论

相关推荐

我见java多妩媚:大外包
点赞 评论 收藏
分享
kyw_:接好运
点赞 评论 收藏
分享
评论
点赞
收藏
分享
正在热议
# 25届秋招总结 #
440577次浏览 4493人参与
# 春招别灰心,我们一人来一句鼓励 #
41484次浏览 524人参与
# 阿里云管培生offer #
119866次浏览 2219人参与
# 地方国企笔面经互助 #
7928次浏览 18人参与
# 同bg的你秋招战况如何? #
75577次浏览 552人参与
# 虾皮求职进展汇总 #
114215次浏览 884人参与
# 北方华创开奖 #
107311次浏览 599人参与
# 实习,投递多份简历没人回复怎么办 #
2454001次浏览 34848人参与
# 实习必须要去大厂吗? #
55678次浏览 960人参与
# 提前批简历挂麻了怎么办 #
149825次浏览 1977人参与
# 投递实习岗位前的准备 #
1195707次浏览 18546人参与
# 你投递的公司有几家约面了? #
33180次浏览 188人参与
# 双非本科求职如何逆袭 #
661910次浏览 7394人参与
# 如果公司给你放一天假,你会怎么度过? #
4730次浏览 55人参与
# 机械人春招想让哪家公司来捞你? #
157604次浏览 2267人参与
# 如果你有一天可以担任公司的CEO,你会做哪三件事? #
11365次浏览 270人参与
# 发工资后,你做的第一件事是什么 #
12418次浏览 61人参与
# 工作中,努力重要还是选择重要? #
35612次浏览 384人参与
# 参加完秋招的机械人,还参加春招吗? #
20091次浏览 240人参与
# 我的上岸简历长这样 #
451924次浏览 8088人参与
# 实习想申请秋招offer,能不能argue薪资 #
39235次浏览 314人参与
# 非技术岗是怎么找实习的 #
155850次浏览 2120人参与
牛客网
牛客企业服务