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 .每 ...
随机推荐
- Hibernate项目的基本步骤和一些错误提示
以数据库中有一张user表为例: 1.编写POJO持久化类User.javaPOJO(Plain Old Java Objects),简单的Java对象.一个POJO类不用继承任何类,也无须实现任何接 ...
- c数据结构 -- 线性表之 复杂的链式存储结构
复杂的链式存储结构 循环链表 定义:是一种头尾相接的链表(即表中最后一个结点的指针域指向头结点,整个链表形成一个环) 优点:从表中任一节点出发均可找到表中其他结点 注意:涉及遍历操作时,终止条件是判断 ...
- 普及C组第四题(8.18)
1574. [提高]X-因子链 (File IO): input:factor.in output:factor.out 时间限制: 1000 ms 空间限制: 131072 KB 题目描述 给一个 ...
- 结构struct 联合Union和枚举Enum的细节讨论
联合(Union)是一种构造数据类型,它提供了一种使不同类型数据类型成员之间共享存储空间的方法,同时可以实现不同类型数据成员之间的自动类型转换.联合体对象在同一时间只能存储一个成员的值.联合的内存大小 ...
- bzoj4765: 普通计算姬 (分块 && BIT)
最近一直在刷分块啊 似乎感觉分块和BIT是超级棒的搭档啊 这道题首先用dfs预处理一下 得到每一个sum值 此时查询是O(1)的 (前缀和乱搞什么的 但是修改需要O(n) (需要修改该节点所有祖先的 ...
- [lua]紫猫lua教程-命令宝典-L1-03-01. 闭包
L1[闭包]01. 函数的传递赋值 没什么说的 1.函数作为变量来看 可以轻松的声明 相互赋值 2.函数变量本质是 一个内存指针 所以函数变量的相互赋值不是传递的函数本身 而是指向这个函数的内存地址 ...
- 【C语言】用C语言输出“心形”图案
在你们的世界里,是不是觉得程序猿一点浪漫都不懂?其实不是的,程序猿的世界也是很浪漫滴! 傻瓜版 int main() { printf("❤"); ; } 高级版 //版本一:单个 ...
- Web 安全工具篇:Burp Suite 使用指南
真的是一点都不过分,了解详情请继续往下读. Burp Suite 介绍 Burp Suite 是用于攻击 web 应用程序的集成平台.它包含了许多工具,并为这些工具设计了许多接口,以促进加快攻击应用程 ...
- php自制工具函数,常用的函数集合
字符串与爬虫相关 1,解析url /** * 模拟访问,可get可post * @param $curl * @param $postInfo post数组/字符串,不填默认没有post * @par ...
- win7 安装asp.net v4.0
错误信息影响: HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容.返回的错误表明IIS缺少针对无后缀的MVC请求的映射,ASP.NET处理程序无法接收到请 ...