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

 

全部评论

相关推荐

05-04 09:38
已编辑
门头沟学院 引擎开发
个人9本海硕,本硕期间一直在投游戏相关实习/校招,岗位由客户端-&gt;引擎-&gt;TA-&gt;AIGC。最终目标肯定是独游制作人,所以程序策划美术都点了些,感觉也没谁了。值此春招末尾总结下技术向校招要点,算是回馈牛客社区了。也附上我的Github和个人博客,欢迎各种交流讨论。&nbsp;前言&nbsp;首先是个人惯例的劝退游戏行业。参见缅怀故人&nbsp;和永远有多远&nbsp;,相比于互联网,游戏薪资大概相当但要求更高,加班严重且更为局限。如果你只是带着一腔热情想入这行,建议先找个日常实习了解下真实的游戏行业再做选择。&nbsp;准备&nbsp;当然,在你决定踏出这步后,第一步就是准备相关的笔试面试。这里先建议找到你感兴趣的公司岗位的JD,然后...
牛客28967172...:说的还是有道理的,我校招时就拿到过网易雷火好几个顶级项目组方向的offer,基本上流程和你说的一样。 但本质还是劝退互联网的游戏方向,本质上是代价更高,而且职业生涯容错率很低,方向比较窄。 代价是众所周知的严重加班,游戏大版本赶工基本上通宵无休,甚至国庆五一都没放假是常态。 职业生涯性价比低是因为游戏行业本质上就是赢家通吃,但你要跳槽只有腾讯网易等头部,要么就是米哈游莉莉丝库洛三七等少数中厂,然后就没了,公司是断崖的少 游戏开发相比互联网方向岗位非常非常少,比如网易整个雷火也才五六百人,里面十几个工作室,招人比例非常低,其他游戏公司也是一样。 而且方向也很窄,你做引擎开发就只能跳相关,你做游戏客户端也只能跳相关(游戏客户端都算吃香的,但市场hc也非常非常少,跳槽机会更少),基本上很难转回互联网 这里对比传统互联网,大厂多的都说不过来,而且容错率很大,你做搜索方向可以跳推荐,你做推荐方向可以跳广告,要求远没有游戏行业那么严,甚至你之前干测试都能跳槽研发方向
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务