CF1166A.Silent Classroom
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n students in the first grade of Nlogonia high school. The principal wishes to split the students into two classrooms (each student must be in exactly one of the classrooms). Two distinct students whose name starts with the same letter will be chatty if they are put in the same classroom (because they must have a lot in common). Let x be the number of such pairs of students in a split. Pairs (a,b) and (b,a) are the same and counted only once.
For example, if there are 6 students: "olivia", "jacob", "tanya", "jack", "oliver" and "jessica", then:
- splitting into two classrooms ("jack", "jacob", "jessica", "tanya") and ("olivia", "oliver") will give x=4 (3 chatting pairs in the first classroom, 1 chatting pair in the second classroom),
- splitting into two classrooms ("jack", "tanya", "olivia") and ("jessica", "oliver", "jacob") will give x=1 (0 chatting pairs in the first classroom, 1 chatting pair in the second classroom).
You are given the list of the n names. What is the minimum x we can obtain by splitting the students into classrooms?
Note that it is valid to place all of the students in one of the classrooms, leaving the other one empty.
Nlogonia 高中一年级共有 n 名学生。校长希望将这些学生分配到两个教室中(每名学生必须且只能被分到其中一个教室)。如果两名不同学生的姓名以相同的字母开头,且他们被分到了同一个教室,则这两名学生会变得“健谈”(因为他们必然有很多共同点)。设 x 为某一分配方案中此类“健谈”学生对的数量。注意:对 (a,b) 和 (b,a) 被视为同一对,仅计一次。
例如,若有 6 名学生:“olivia”、“jacob”、“tanya”、“jack”、“oliver” 和 “jessica”,则:
- 将学生分为两个教室:("jack", "jacob", "jessica", "tanya") 和 ("olivia", "oliver"),此时 x=4(第一个教室中有 3 对健谈学生,第二个教室中有 1 对健谈学生);
- 将学生分为两个教室:("jack", "tanya", "olivia") 和 ("jessica", "oliver", "jacob"),此时 x=1(第一个教室中无健谈学生对,第二个教室中有 1 对健谈学生)。
现给出这 n 名学生的姓名列表。通过将学生分配到两个教室,所能得到的最小 x 值是多少?
注意:允许将所有学生都分到同一个教室,而令另一个教室为空。
输入格式
The first line contains a single integer n (1≤n≤100) — the number of students.
After this n lines follow.
The i-th line contains the name of the i-th student.
It is guaranteed each name is a string of lowercase English letters of length at most 20. Note that multiple students may share the same name.
第一行包含一个整数 n(1≤n≤100)—— 学生人数。
接下来是 n 行。
第 i 行包含第 i 个学生的姓名。
保证每个姓名均由至多 20 个小写英文字母组成的字符串。注意,多个学生可能具有相同的姓名。
输出格式
The output must consist of a single integer x — the minimum possible number of chatty pairs.
输出必须为一个整数 x —— 可能的健谈对的最小数量。
输入输出样例
输入#1
4 jorge jose oscar jerry
输出#1
1
输入#2
7 kambei gorobei shichiroji kyuzo heihachi katsushiro kikuchiyo
输出#2
2
输入#3
5 mike mike mike mike mike
输出#3
4
说明/提示
In the first sample the minimum number of pairs is 1. This can be achieved, for example, by putting everyone except jose in one classroom, and jose in the other, so jorge and jerry form the only chatty pair.
In the second sample the minimum number of pairs is 2. This can be achieved, for example, by putting kambei, gorobei, shichiroji and kyuzo in one room and putting heihachi, katsushiro and kikuchiyo in the other room. In this case the two pairs are kambei and kyuzo, and katsushiro and kikuchiyo.
In the third sample the minimum number of pairs is 4. This can be achieved by placing three of the students named mike in one classroom and the other two students in another classroom. Thus there will be three chatty pairs in one classroom and one chatty pair in the other classroom.
在第一个样例中,最少的搭伴数量为 1。例如,可将除 jose 外的所有人安排在一个教室,jose 单独安排在另一个教室,这样 jorge 和 jerry 就构成了唯一的一对爱说话的搭档。
在第二个样例中,最少的搭伴数量为 2。例如,可将 kambei、gorobei、shichiroji 和 kyuzo 安排在一个教室,将 heihachi、katsushiro 和 kikuchiyo 安排在另一个教室。此时,两对爱说话的搭档分别是 kambei 和 kyuzo,以及 katsushiro 和 kikuchiyo。
在第三个样例中,最少的搭伴数量为 4。可通过将三名名为 mike 的学生安排在一个教室、另外两名学生安排在另一个教室来实现。这样,一个教室中有三对爱说话的搭档,另一个教室中有一对爱说话的搭档。
输入解题思路,AI测评打分。不知道怎么写?