codeforces 1287A -Angry Students(模拟)
It’s a walking tour day in SIS.Winter, so t 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 i in the string describing a group then they will throw a snowball at the student that corresponds to the character with index i+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.
Input
The first line contains a single integer t — the number of groups of students (1≤t≤100). The following 2t lines contain descriptions of groups of students.
The description of the group starts with an integer ki (1≤ki≤100) — the number of students in the group, followed by a string si, consisting of ki letters “A” and “P”, which describes the i-th group of students.
Output
For every group output single integer — the last moment a student becomes angry.
Examples
Input
1
4
PPAP
Output
1
Input
3
12
APPAPPPAPPPP
3
AAP
3
PPA
Output
4
1
0
Note
In the first test, after 1 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 1 minute — AAPAAPPAAPPP
after 2 minutes — AAAAAAPAAAPP
after 3 minutes — AAAAAAAAAAAP
after 4 minutes all 12 students are angry
In the second group after 1 minute, all students are angry.
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
string s;
int k,t;
int main()
{
read(t);
while (t--)
{
read(k);
cin >> s;
int count = 0, max = 0, flag = 0;
for (int i = 0; i < k;)
if (s[i] == 'A')
{
count = 0, i++;
while (s[i] == 'P')
count++, i++;
if (count > max)
max = count;
}
else
i++;
wi(max);
P;
}
return 0;
}
codeforces 1287A -Angry Students(模拟)的更多相关文章
- A. Angry Students
网址:http://codeforces.com/problemset/problem/1287/A It's a walking tour day in SIS.Winter, so tt grou ...
- [模拟]Codeforces Circle of Students
Circle of Students time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- 【Codeforces 332C】Students' Revenge
Codeforces 332 C 我爱对拍,对拍使我快乐... 题意:有\(n\)个议题,学生们会让议会同意\(p\)个,其中主席会执行\(k\)个, 每一个议题执行后主席会掉\(a_i\)的头发,不 ...
- Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...
随机推荐
- 好玩Python——PIL项目实训
PIL学习总结: 1. 2,PIL库概述: pil库可以完成图像归档和图像处理两方面功能的需求: 图像归档:对图像进行批处理,生成图像预览,图像转换格式等: 图像处理:图像基本处理,像素处理,颜色处理 ...
- docker-compose中加入nginx 日志和部署下载
服务器部署了nginx镜像,所以加入一个日志查看,添加一下静态页面下载. 1.查看nginx镜像怎么部署的 nginx: image: nginx ports: - '80:80' volumes: ...
- go 切片重组
我们已经知道切片创建的时候通常比相关数组小,例如: slice1 := make([]type, start_length, capacity) 其中 start_length 作为切片初始长度而 c ...
- "字体图标"组件:<icon> —— 快应用组件库H-UI
 <import name="icon" src="../Common/ui/h-ui/basic/c_icon"></import> ...
- tf.nn.depthwise_conv2d 卷积
tf.nn.depthwise_conv2d( input, filter, strides, padding, rate=None, name=None, data_format=None ) 参数 ...
- java 方法 在jvm中的调用
java 某个类的几个对象,这些对象调用类中一个函数,是各自拥有自己的函数代码还是使用同一段代码?30 1.java 某个类的几个对象,这些对象调用类中一个函数(普通的函数),是各自拥有自己的函数代码 ...
- TensorFlow保存、加载模型参数 | 原理描述及踩坑经验总结
写在前面 我之前使用的LSTM计算单元是根据其前向传播的计算公式手动实现的,这两天想要和TensorFlow自带的tf.nn.rnn_cell.BasicLSTMCell()比较一下,看看哪个训练速度 ...
- 数据结构和算法(Golang实现)(23)排序算法-归并排序
归并排序 归并排序是一种分治策略的排序算法.它是一种比较特殊的排序算法,通过递归地先使每个子序列有序,再将两个有序的序列进行合并成一个有序的序列. 归并排序首先由著名的现代计算机之父John_von_ ...
- AJ学IOS(09)UI之UIScrollView代理触摸实现_图片缩放
AJ分享,必须精品 先看效果 代码 // // NYViewController.m // 05-放大缩小图片UIScrollView // // Created by apple on 15-3-2 ...
- three.js中让模型自动居中的代码如下:
//load_Model为需要居中的3D模型 //原理是通过boundingBoxHelper 来计算模型的大小范围 var hex = 0xff0000; var MD_Length,MD_Widt ...