CF65D.Harry Potter and the Sorting Hat

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

As you know, Hogwarts has four houses: Gryffindor, Hufflepuff, Ravenclaw and Slytherin. The sorting of the first-years into houses is done by the Sorting Hat. The pupils are called one by one in the alphabetical order, each of them should put a hat on his head and, after some thought, the hat solemnly announces the name of the house the student should enter.

At that the Hat is believed to base its considerations on the student's personal qualities: it sends the brave and noble ones to Gryffindor, the smart and shrewd ones — to Ravenclaw, the persistent and honest ones — to Hufflepuff and the clever and cunning ones — to Slytherin. However, a first year student Hermione Granger got very concerned about the forthcoming sorting. She studied all the literature on the Sorting Hat and came to the conclusion that it is much simpler than that. If the relatives of the student have already studied at Hogwarts, the hat puts the student to the same house, where his family used to study. In controversial situations, when the relatives studied in different houses or when they were all Muggles like Hermione's parents, then the Hat sorts the student to the house, to which the least number of first years has been sent at that moment. If there are several such houses, the choice is given to the student himself. Then the student can choose any of the houses, to which the least number of first years has been sent so far.

Hermione has already asked the students that are on the list before her about their relatives. Now she and her new friends Harry Potter and Ron Weasley want to find out into what house the Hat will put Hermione.

众所周知,霍格沃茨有四个学院:格兰芬多、赫奇帕奇、拉文克劳和斯莱特林。一年级新生的分院由分院帽完成。学生们按姓名字母顺序依次被叫到,每人将帽子戴在头上,经过一番思考后,帽子会庄严地宣布该学生应进入的学院。

据信,分院帽的决定依据是学生的个人品质:它将勇敢而高贵的学生送往格兰芬多,将聪慧而机敏的学生送往拉文克劳,将坚毅而诚实的学生送往赫奇帕奇,将精明而狡黠的学生送往斯莱特林。然而,一年级新生赫敏·格兰杰却对即将到来的分院感到十分担忧。她研读了所有关于分院帽的文献,并得出结论:实际情况远比上述描述简单得多。如果学生的亲属此前曾在霍格沃茨就读过,那么分院帽便会将该学生分入其亲属曾经所在的学院。在存在争议的情况下(例如亲属曾就读于不同学院,或像赫敏的父母那样全为麻瓜),分院帽则会将该学生分入当前已分配的一年级新生人数最少的学院。若存在多个这样的学院,则由学生本人自行选择;此时,学生可任选一个当前已分配的一年级新生人数最少的学院。

赫敏已向排在自己前面的学生们询问过他们亲属的情况。现在,她与她的新朋友哈利·波特和罗恩·韦斯莱想弄清楚:分院帽究竟会将赫敏分入哪个学院?

输入格式

The first input line contains an integer n (1 ≤ n ≤ 10000). It is the number of students who are in the list before Hermione. The next line contains n symbols. If all the relatives of a student used to study in the same house, then the i-th character in the string coincides with the first letter of the name of this house. Otherwise, the i-th symbol is equal to "?".

第一行输入包含一个整数 nn(1≤n≤100001 \leq n \leq 10000),表示在赫敏之前名单上的学生人数。
下一行包含 nn 个字符。如果某位学生的全部亲属曾经都在同一学院就读,则该字符串中第 ii 个字符等于该学院名称的首字母;否则,第 ii 个字符为 ?。

输出格式

Print all the possible houses where Hermione can be sent. The names of the houses should be printed in the alphabetical order, one per line.

打印赫敏可能被分入的所有学院。学院名称应按字母顺序排列,每行一个。

输入输出样例

  • 输入#1

    11
    G????SS???H

    输出#1

    Gryffindor
    Ravenclaw
  • 输入#2

    2
    H?

    输出#2

    Gryffindor
    Ravenclaw
    Slytherin

说明/提示

Consider the second example. There are only two students before Hermione. The first student is sent to Hufflepuff. The second disciple is given the choice between the houses where the least number of students has been sent, i.e. Gryffindor, Slytherin and Ravenclaw. If he chooses Gryffindor, Hermione is forced to choose between Ravenclaw and Slytherin, if he chooses Ravenclaw, Hermione will choose between Gryffindor and Slytherin, if he chooses Slytherin, Hermione will choose between Gryffindor and Ravenclaw. In the end, the following situation is possible (it depends on the choice of the second student and Hermione). Hermione will end up 1) in Gryffindor, 2) in Ravenclaw, 3) in Slytherin. Note that, despite the fact that in neither case Hermione will be given a choice between all the three options, they are all possible and they should all be printed in the answer. Hermione will not, under any circumstances, end up in Hufflepuff.

考虑第二个例子。在赫敏之前只有两名学生。第一名学生被分入赫奇帕奇。第二名学生则需在学生人数最少的学院中进行选择,即格兰芬多、斯莱特林和拉文克劳。如果他选择格兰芬多,则赫敏只能在拉文克劳和斯莱特林之间选择;如果他选择拉文克劳,则赫敏将在格兰芬多和斯莱特林之间选择;如果他选择斯莱特林,则赫敏将在格兰芬多和拉文克劳之间选择。最终可能出现以下情况(具体取决于第二名学生及赫敏的选择):赫敏最终将进入 1) 格兰芬多,2) 拉文克劳,3) 斯莱特林。注意:尽管在任何一种情况下,赫敏都不会面临全部三个选项的选择,但这三种结果均有可能发生,因此答案中必须全部列出。赫敏在任何情况下都不会被分入赫奇帕奇。

输入解题思路,AI测评打分。不知道怎么写?

首页