Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)
A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output 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.
Input 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.
Output The output must consist of a single integer x — the minimum possible number of chatty pairs.
Examples inputCopy 4 jorge jose oscar jerry outputCopy 1 inputCopy 7 kambei gorobei shichiroji kyuzo heihachi katsushiro kikuchiyo outputCopy 2 inputCopy 5 mike mike mike mike mike outputCopy 4 Note 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 student
#include<stdio.h>
#include<string.h>
int main()
{
static int kk[26];
int n, c, k, ans;
scanf("%d", &n);
while (n--)
{
static char s[32];
scanf("%s", s);
kk[s[0] - 'a']++;
}
ans = 0;
for (c = 0; c < 26; c++)
{
k = kk[c] / 2;
ans += k * (k - 1) / 2 + (kk[c] - k) * (kk[c] - k - 1) / 2;
}
printf("%dn", ans);
return 0;
}
- Isolation Forest算法实现详解
- css继承样式怎么控制?用选择器
- wordpress站内搜索结果页URL伪静态如何操作
- 如何实现大图居中超过的部分两边自动隐藏
- Ubuntu16.04安装后开发环境配置和常用软件安装
- wordpress如何屏蔽wp-json(禁用REST API)
- 贝叶斯系列——贝叶斯与其他统计流派的区别和联系
- bootstrap tab切换如何让鼠标移动自动切换内容
- css自动换行如何设置?url太长会撑开页面
- Histogram of Oriented Gridients(HOG) 方向梯度直方图
- 动态规划系列之最长递增子序列问题解答
- Git SSH Key 生成步骤
- 如何将wordpress所有文章批量改为已发布状态
- dedecms提取某栏目及子栏目名称到首页怎么弄
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- dotnet 在 UOS 国产系统上安装 MonoDevelop 开发工具
- 使用SAP Spartacus快速创建一个电商店铺网站
- 使用StackBlitz和SAP Spartacus快速创建电商店铺页面
- SAP CRM Interactive Report(交互式报表)里和服务订单相关的一些字段
- SAP S/4HANA Customer Management(CRM)模块的扩展性设计
- SAP S/4HANA Customer Management(CRM)模块的Partner模型设计
- 使用soapUI消费SAP Cloud for Customer的web service
- 视频上云网关EasyNTS智能云组网如何通过23端口穿透实现远程控制功能?
- 视频上云网关平台EasyCVR登录页开发控制台报net::ERR_CONNECTION_TIMED_OUT错误
- 视频监控系统视频上云解决方案EasyCVR集成海康EHome私有协议系列——开启存储服务
- 设计模式~责任链模式
- 大数据计算的基石——MapReduce
- SPA单页应用的优缺点
- 《JavaScript 模式》读书笔记(7)— 设计模式1
- CenterNet测试推理过程