A12625 | Silent Classroom
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains a single integer $n$ ( $1\leq n \leq 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.
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.
输出格式
The output must consist of a single integer $x$ — the minimum possible number of chatty pairs.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted