A. Angry Students
网址:http://codeforces.com/problemset/problem/1287/A
It's a walking tour day in SIS.Winter, so tt groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.
Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":
- "A" corresponds to an angry student
- "P" corresponds to a patient student
Such string describes the row from the last to the first student.
Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index ii in the string describing a group then they will throw a snowball at the student that corresponds to the character with index i+1i+1 (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.

Let's look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.
Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.
The first line contains a single integer tt — the number of groups of students (1≤t≤1001≤t≤100 ). The following 2t2t lines contain descriptions of groups of students.
The description of the group starts with an integer kiki (1≤ki≤1001≤ki≤100 ) — the number of students in the group, followed by a string sisi , consisting of kiki letters "A" and "P", which describes the ii -th group of students.
For every group output single integer — the last moment a student becomes angry.
1
4
PPAP
1
3
12
APPAPPPAPPPP
3
AAP
3
PPA
4
1
0
In the first test, after 11 minute the state of students becomes PPAA. After that, no new angry students will appear.
In the second tets, state of students in the first group is:
- after 11 minute — AAPAAPPAAPPP
- after 22 minutes — AAAAAAPAAAPP
- after 33 minutes — AAAAAAAAAAAP
- after 44 minutes all 1212 students are angry
In the second group after 11 minute, all students are angry.
解题思路:
就是在字符串中找A并且向后枚举,找他能向后传染的最大值
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
inline int read() {int x=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
typedef long long ll;
const int maxn = 1e7+;
char a[maxn];
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
scanf("%s",a);
int ans=;
int k=;
for(int i=;i<n;i++){
if(a[i]=='A'){
while(a[i+]=='P'){
k++;
i++;
}
}
ans=max(k,ans);
k=;
}
printf("%d\n",ans);
}
return ;
}
A. Angry Students的更多相关文章
- codeforces 1287A -Angry Students(模拟)
It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torz ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #612 (Div. 2)
https://codeforces.com/contest/1287/ A - Angry Students 题意:求A后面的P最长连续有几个? 题解:? int n; char s[200005] ...
- Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you are Angry.Think Twice.Act Wise.
Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you ...
- Advice for students of machine learning--转
原文地址:http://www.mimno.org/articles/ml-learn/ written by david mimno One of my students recently aske ...
- HDOJ 2444 The Accomodation of Students
染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
- Spring-2-B Save the Students(SPOJ AMR11B)解题报告及测试数据
Save the Students Time Limit:134MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descri ...
- HD2444The Accomodation of Students(并查集判断二分图+匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- codeforces A. Group of Students 解题报告
题目链接:http://codeforces.com/problemset/problem/357/A 题目意思:将一堆人分成两组:beginners 和 intermediate coders .每 ...
随机推荐
- Binary Number(位运算)
#include<bits/stdc++.h> using namespace std; int n; int getBits1(int n)//求取一个数的二进制形式中1的个数. { i ...
- django 搭建一个投票类网站(二)
前一篇讲了创建一个工程和一个polls的应用程序,以及配置了数据库. 这篇就继续讲吧 1.django admin模块 admin模块是django自带的模块,他让开发者可以不用管写任何代码的情况下就 ...
- WPF学习笔记二之依赖属性
1.快捷生成依赖属性:propdp然后按两次tab键 2.应用场景:自定义控件 什么是依赖属性:依赖属性自己没有值,通过依赖别人(如Binding)来获得值. 依赖属性为什么会出现:控件常用字段有限, ...
- csrf跨站点请求伪造
什么是csrf(跨站请求伪造) 伪造请求的定义有很多种,我将不是用户本意发出的请求统称为伪造请求(在用户不知情的情况下执行某些操作)xss的通过用户对浏览器的信任造成的,csrf是通过服务器对浏览器的 ...
- python之路之线程,进程,协程2
一.线程 1.创建线程 2.主线程是否等待子线程 t.setDaemon(Ture/False):默认是false,等待子线程完成,ture,表示不等待子线程结束 3.主线程等待,子线程执行 join ...
- 2.springboot------微服务
什么是微服务? 微服务是一种架构风格,它要求我们在开发一个应用的时候,这个应用必须构建成一系列小服务的组合:可以通过http的方式进行互通.要说微服务架构,先得说说过去我们的单体应用架构. 单体应用架 ...
- Coloring Colorfully
问题 C: Coloring Colorfully 时间限制: 1 Sec 内存限制: 128 MB[提交] [状态] 题目描述 N块瓦片从左到右排成一行.每个块的初始颜色由长度为N的字符串S表示. ...
- (c#)最小绝对差
题目 解
- SQL 杂项
select * from 表 where to_date(ksrq,'yyyy-MM-dd')<=sysdate and sysdate <= to_date(jsrq,'yy ...
- Mongodb学习笔记(二)Capped Collection固定集合
一.Capped Collection固定集合 简单介绍 capped collections是性能出色的有着固定大小的集合(定容集合),以LRU(Least Recently Used最近最少使用) ...