Codeforces Round #193 (Div. 2) A Down the Hatch!
来源:互联网 发布:扬天智汇中心软件下载 编辑:程序博客网 时间:2024/05/16 23:40
/*
唔,这场比赛居然11点半才开始,那个时候我和萌神在看越狱第二季。比赛快结束的时候我躺下准备睡觉,看到韬神发说说说A题看不懂,然后用手机上cf看了一下
A题很好理解嘛。然后我就和喵呜讲了我的思路,他说和大神的很接近,唔,于是睡觉。
然后刚才爬起来花了两分钟码了一下代码,交上去就AC了,开心~
*/
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.
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.
简述一下题目意思吧,Vasya这货和他的小伙伴们共n个人围成一个圈玩游戏,他的编号是0.从Vasya开始turn1.
轮到行动的人要point你下一个人(bi+1)mod n的话正好一圈人一个循环(0,1,2....n-1,n,0,1,2...)做出的动作是elbow(a)还是nod(b)
然后就是你行动是point的动作,和你前三个人point的动作一样的话就可以drink a glass of juice.
由于Vasya开了挂,他能改变他point下一个人的动作,其他人的不变,让你求挂比能喝的最大juice数。
解题方法:
很简单,从第二次Vasya行动开始,如果他前面3个人的行动一样,就可以喝一瓶。
代码:
# 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;}
- Codeforces Round #193 (Div. 2) A Down the Hatch!
- Codeforces Round #193 (Div. 2) / 332A Down the Hatch! (模拟)
- CodeForces 332A Down the Hatch!
- A. Down the Hatch!
- cf 193 div2 A. Down the Hatch!
- cf——A. Down the Hatch!
- CF 332 A.Down the Hatch【模拟】
- cf_332A - Down the Hatch!(水题)
- Codeforces Round #198 (Div. 2) A. The Wall
- Codeforces Round #198 (Div. 2) / 340A The Wall (数论)
- Codeforces Round #198(Div. 2)A. The Wall
- Codeforces Round #250 (Div. 2) A. The Child and Homework
- Codeforces Round #250 (Div. 2) A - The Child and Homework
- Codeforces Round #322 (Div. 2)A. Vasya the Hipster
- Codeforces Round #342 (Div. 2)--A. Guest From the Past
- Codeforces Round #342 (Div. 2)-A. Guest From the Past
- Codeforces Round #373 (Div. 2) A. Vitya in the Countryside
- Codeforces Round #373 (Div. 2) A.Vitya in the Countryside
- 关于stride跨距的问题
- 【转】Maven - 坐标
- Unity3D 游戏引擎之实现平面多点触摸(二)
- 64位weblogic11g安装
- Java画水晶球
- Codeforces Round #193 (Div. 2) A Down the Hatch!
- 很好的JS效果,收藏之
- PHP:获取指定日期所在月的开始日期与结束日期
- $(":submit[id=submit01]").click(function(check){
- QT中文字体显示以及字体大小不能改变的问题
- ORA-00054
- win7部署程序到模拟器上出错:无法连接到设备,错误:0x8007064a
- 从零开始学C++之STL(五):非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
- 高质量视频学习网站