当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6261:Rikka with Mutex

题目描述
Sometimes, technical terms implicate some life philosophy. Mutex is one of them. On your way to dream, you may be locked by some difficulties, and you need someone to stop his step, and help you get through them.

To help you know better about the life philosophy inside mutex, Rikka comes up with a simple task. Maybe some of you know little about mutex, so she uses another scene to replace it.

There are $n$ gates in a row, several people in the left side of the gates and all of them want to go to the right side. There are two kinds of gates: black and white. These people share energy, which is represented by a non-negative number $E$. Initially, $E =0 $.

If one person walks through a white gate, he will gain one point of energy, i.e., $E$ will be added by $1$. And if one person walks through a black gate, he will lose one point of energy, i.e., $E$ will be subtracted by $1$. Since $E$ must be a non-negative integer, if $E=0$, no one can walk through a black gate until someone walks through a white gate. You can assume there won't be two people moving at the same time and all the people are selfless.

We use P to represent a black gate, V to represent a white gate and use a PV string to represent the row. Initially, all the people are at the beginning of the string, and all of them want to go through the whole string. But unfortunately, sometimes it may be impossible. So, they want to send at least one person to the right side.

Your task is to find out the minimal number of people which this group needs to achieve this goal.

For example, if the row is VPP, they need at least two people: The first person walk through the first white gate and the second person can use this point of energy to go through the whole string.
输入解释
The first line contains a single numner $t(1 \leq t \leq 10^3)$, the number of the testcases.

For each testcase, the first line contains a PV string $s(1 \leq |s| \leq 10^5)$ describing the gates.

The input guarantees that there are at most $30$ testcases with $|S| > 1000$.
输出解释
For each testcase, output a single integer, the answer. And if it is impossible, output $-1$.

输入样例
4
VPP
VPPVVVVPPPPPPPP
VPPPPPPPPPPPPPP
P
输出样例
2
3
14
-1
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6261

最后修改于 2020-10-25T23:29:47+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 512000/512000K(Java/Others)