链接:https://codeforces.com/contest/1166/problem/A

题意:

There are nn 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 xx be the number of such pairs of students in a split. Pairs (a,b)(a,b) and (b,a)(b,a) are the same and counted only once.

For example, if there are 66 students: "olivia", "jacob", "tanya", "jack", "oliver" and "jessica", then:

  • splitting into two classrooms ("jack", "jacob", "jessica", "tanya") and ("olivia", "oliver") will give x=4x=4 (33 chatting pairs in the first classroom, 11 chatting pair in the second classroom),
  • splitting into two classrooms ("jack", "tanya", "olivia") and ("jessica", "oliver", "jacob") will give x=1x=1 (00 chatting pairs in the first classroom, 11 chatting pair in the second classroom).

You are given the list of the nn names. What is the minimum xx 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.

思路:

计算每个首字母出现的次数,均匀分配到两个教室,求每边的配对数即可。

代码:

#include <bits/stdc++.h>
using namespace std; typedef long long LL; int dic[30]; int main()
{
int n;
string s;
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> s;
char w = s[0];
w = tolower(w);
dic[w-'a']++;
}
int res = 0;
for (int i = 0;i < 26;i++)
{
int l = dic[i]/2;
int r = dic[i]-l;
l--;
r--;
if (l > 0)
res += (1+l)*l/2;
if (r > 0)
res += (1+r)*r/2;
}
cout << res << endl; return 0;
}

  

Codeforces Round #561 (Div. 2) A. Silent Classroom的更多相关文章

  1. Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)

    A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard inp ...

  2. Codeforces Round #561 (Div. 2) C. A Tale of Two Lands

    链接:https://codeforces.com/contest/1166/problem/C 题意: The legend of the foundation of Vectorland talk ...

  3. Codeforces Round #561 (Div. 2) B. All the Vowels Please

    链接:https://codeforces.com/contest/1166/problem/B 题意: Tom loves vowels, and he likes long words with ...

  4. Codeforces Round 561(Div 2)题解

    这是一场失败的比赛. 前三题应该是随便搞的. D有点想法,一直死磕D,一直WA.(赛后发现少减了个1……) 看E那么多人过了,猜了个结论交了真过了. 感觉这次升的不光彩……还是等GR3掉了洗掉这次把, ...

  5. Codeforces Round #561 (Div. 2) E. The LCMs Must be Large(数学)

    传送门 题意: 有 n 个商店,第 i 个商店出售正整数 ai: Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数: Dora 的对手 Swiper 在第 i 天去 ...

  6. Codeforces Round #561 (Div. 2)

    C. A Tale of Two Lands 题意: 给出 n 个数,问有多少点对(x,y)满足 |x-y| ≤ |x|,|y| ≤ |x+y|: (x,y) 和 (y,x) 表示一种答案: 题解: ...

  7. Codeforces Round #561 (Div. 2) A Tale of Two Lands 【二分】

    A Tale of Two Lands 题目链接(点击) The legend of the foundation of Vectorland talks of two integers xx and ...

  8. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

  9. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

随机推荐

  1. ARP之windows下的ARP命令

    ARP之windows下的ARP命令 arp -a 查看当前电脑上的ARP映射表.可以看到当前的ARP的映射关系是动态的还是静态的. arp -s w.x.y.z aa-bb-cc-dd-ee-ff ...

  2. c++的最小整数和最大整数

    #include<iostream> #include<cmath> using namespace std; int main() { //int -2147483648~2 ...

  3. 有时候,Visual C++代码中加中文注释会导致错误!

    今天做题发现了个奇葩错误,以此警戒自己. 张某,做的一道题. --------------------------------------------------------------------- ...

  4. T60

    The smooth contour of the sculpture is wonderful.Her commitment to a great cause degenerated from a ...

  5. linux进程学习笔记

    学习了linux下的进程,觉得应该整理一下,忘得差不多了,顺便回顾一下. 学而时习之,不亦说乎~~ 进程笔记 ,什么是进程? The Single UNIX Specification, Versio ...

  6. jmeter的http post请求与测试Java请求

    1.jmeter 测试Java请求 1.1 建立测试类,在被测程序中添加测试类 1.2 将测试程序打包,打成不可运行的包 1.3 将打好的包,放在$JMETER_HOME/lib/exts下面,把测试 ...

  7. rman理论(一)

    1) 快照控制文件:开始备份后,RMAN 需要这些信息在备份操作期间保持一致,也就是说RMAN需要一个读取一致的控制文件视图. 除非RMAN 在备份持续时间内锁定控制文件,否则数据库会不断更新控制文件 ...

  8. hdu 2222 Keywords Search——AC自动机

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2222 第一道AC自动机! T了无数边后终于知道原来它是把若干询问串建一个自动机,把模式串放在上面跑:而且只 ...

  9. poj1742硬币——多重背包可行性

    题目:http://poj.org/problem?id=1742 贪心地想,1.如果一种面值已经可以被组成,则不再对它更新: 2.对于同一种面值的硬币,尽量用较少硬币(一个)更新,使后面可以用更多此 ...

  10. java对世界各个时区(TimeZone)的通用转换处理方法

    在进行国际性软件项目开发的过程中,有时候会碰到一些比较特殊的要求.比如:比如说,你做的是个购物网站(假设服务器放在中国上海),当全世界客户在你的网站上下订单买东西后,往往希望看到客户所在地下单时间,比 ...