Codeforces Round #561 (Div. 2) A. Silent Classroom
链接: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的更多相关文章
- Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)
A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- 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 ...
- 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 ...
- Codeforces Round 561(Div 2)题解
这是一场失败的比赛. 前三题应该是随便搞的. D有点想法,一直死磕D,一直WA.(赛后发现少减了个1……) 看E那么多人过了,猜了个结论交了真过了. 感觉这次升的不光彩……还是等GR3掉了洗掉这次把, ...
- Codeforces Round #561 (Div. 2) E. The LCMs Must be Large(数学)
传送门 题意: 有 n 个商店,第 i 个商店出售正整数 ai: Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数: Dora 的对手 Swiper 在第 i 天去 ...
- Codeforces Round #561 (Div. 2)
C. A Tale of Two Lands 题意: 给出 n 个数,问有多少点对(x,y)满足 |x-y| ≤ |x|,|y| ≤ |x+y|: (x,y) 和 (y,x) 表示一种答案: 题解: ...
- 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 ...
- 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 题解 直接 ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
随机推荐
- JAVA- 清除数组重复元素
清除数组重复元素并打印新数组. import java.util.*; public class Repeat { public static void main(String[] args) { / ...
- PHP相关安全配置【转】
PHP是广泛使用的开源服务端脚本语言.通过HTTP或HTTPS协议,Apache Web服务允许用户访问文件或内容.服务端脚本语言的错误配置会导致各种问题.因此,PHP应该小心使用.以下是为系统管理员 ...
- Java企业微信开发_10_未验证域名归属,JS-SDK功能受限
1.现象: 在企业微信后台填写可信域名后,提示:未验证域名归属,JS-SDK功能受限,如下图: 点击“申请域名校验”后, 注意:域名根目录 当时一直不清楚这个域名根目录在哪里,最后让我给试出来了 2. ...
- 联系E-R:学生选课系统
- not in和not exist的区别(转)
in和exists in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询.一直以来认为exists比in效率高的说法是不准确的. 如果查询的两个 ...
- listen 75
Hot Jupiters Smarten Search For Other Earths Scientists are looking for Earth like planets around ot ...
- 2012年浙大:Hello World for U
题目描述: Given any string of N (>=5) characters, you are asked to form the characters into the shape ...
- 搭建基于Nagios的监控系统——之监控远程Linux服务器
上一篇介绍了如何安装Nagios Core,这一篇跟大家分享一下如何将一台远程的Linux服务器加入纳入监控范围. 第一部分:在远程Linux上安装Nagios Plugins和NRPE 第一步: ...
- Java 日志记录规则
Java 日志记录规则 规则一:日志是面向读者的 我们不应该让无价值的信息使日志文件变得乱糟糟,比如说完整打印所有的实体字段. 通常,实体名字和其逻辑关键字足以识别在表格中的一条记录了. 规则二:匹配 ...
- Laravel框架之CSRF防跨站攻击
laravel框架的csrf防跨站攻击,简单的意思就是说为了防止别人自己写表单非法提交,非法绕过前台的验证,直接将数据往后台执行. 一般的网站如果没有这些安全措施,比较容易被攻击.当然了也还要有其他的 ...