CF46C.Hamsters and Tigers
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him.
今天马戏团将上演一场别开生面的表演——仓鼠与老虎将同台演出!所有动物都沿着表演场地边缘围成一个圆圈站立。此时,驯兽师面临一项艰巨任务:他希望交换动物的位置,使得所有仓鼠彼此相邻、所有老虎也彼此相邻。为避免现场混乱,驯兽师每次仅交换一对动物的位置:他命令两只动物离开圆圈并互换位置。由于仓鼠在老虎附近会感到极度不适,而老虎在大量潜在猎物(不仅包括仓鼠,还有更可口的观众)周围也会紧张,因此驯兽师希望尽可能缩短动物移动所需时间,即用最少的交换次数达成目标。你的任务就是协助他完成这一目标。
输入格式
The first line contains number n (2 ≤ n ≤ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one.
第一行包含一个数字 n(2 ≤ n ≤ 1000),表示竞技场中动物的总数。
第二行描述了动物的位置,由 n 个字符 "H" 和 "T" 组成。其中 "H" 表示仓鼠,"T" 表示老虎。题目保证竞技场中至少有一只仓鼠和一只老虎。
动物按顺时针(或逆时针)环形排列给出,且最后一只动物与第一只动物相邻。
输出格式
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
输出一个数字,即训练师达成目标所需的最少交换次数。
输入输出样例
输入#1
3 HTH
输出#1
0
输入#2
9 HTHTHTHHT
输出#2
2
说明/提示
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
在第一个例子中,我们不应移动任何人,因为每种动物已经与其他种类的动物彼此分离。在第二个例子中,您可以交换,例如,位置 2 处的老虎与位置 5 处的仓鼠,然后——位置 9 处的老虎与位置 7 处的仓鼠。
输入解题思路,AI测评打分。不知道怎么写?