Codeforces Round #263 (Div. 2) proB
题目:
1 second
256 megabytes
standard input
standard output
Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards
from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calculate
how much Toastman's cards have the letter equal to letter on ith, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105).
The next line contains n uppercase letters without spaces — the i-th
letter describes the i-th card of the Appleman.
Print a single integer – the answer to the problem.
15 10
DZFDFZDFDDDDDDF
82
6 4
YJSNPI
4
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he
will get 9 coins and for the additional card he will get 1 coin.
题意分析:
能够得的分数是卡数的平分,求最大分数。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[110000];
int j[500],cn[500];
void solve()
{
int n,k;
long long ans=0;
scanf("%d%d",&n,&k);
scanf("%s",s);
int len=strlen(s);
for(int i=0; i<len; i++)
{
j[s[i]]++;
}
while(k)
{
k--;
int w=0,Max=0;
for(int i='A'; i<='Z'; i++)
{
if(j[i]>Max&&cn[i]<j[i])
{
Max=j[i];
w=i;
}
}
cn[w]++;
}
for(int i='A'; i<='Z'; i++)
{
ans+=1LL*cn[i]*cn[i];
}
cout<<ans<<endl;
}
int main()
{
solve();
return 0;
}
Codeforces Round #263 (Div. 2) proB的更多相关文章
- 贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman
题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :R ...
- Codeforces Round #263 (Div. 2)
吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...
- Codeforces Round #263 (Div. 1)
B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] ...
- Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】
题意:给了一棵树以及每个节点的颜色,1代表黑,0代表白,求将这棵树拆成k棵树,使得每棵树恰好有一个黑色节点的方法数 解法:树形DP问题.定义: dp[u][0]表示以u为根的子树对父亲的贡献为0 dp ...
- Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)
题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...
- Codeforces Round #263 (Div. 2) A B C
题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput ...
- Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新
C. Appleman and a Sheet of Paper Appleman has a very big sheet of paper. This sheet has a form of ...
- Codeforces Round #263 (Div. 2) proC
题目: C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #263 (Div. 2)C(贪心,联想到huffman算法)
数学家伯利亚在<怎样解题>里说过的解题步骤第二步就是迅速想到与该题有关的原型题.(积累的重要性!) 对于这道题,可以发现其实和huffman算法的思想很相似(可能出题人就是照着改编的).当 ...
随机推荐
- python 对比两个字典的差异
实际遇到的问题逻辑很繁杂,就不全写了.最后是通过对比两个字典差异来解决的.找出两个字典的差异,可参考以下代码. dict1 = {'a':1,'b':2,'c':3,'d':4} dict2 = {' ...
- Vijos P1404 遭遇战
背景 你知道吗,SQ Class的人都很喜欢打CS.(不知道CS是什么的人不用参加这次比赛). 描述 今天,他们在打一张叫DUSTII的地图,万恶的恐怖分子要炸掉藏在A区的SQC论坛服务器!我们SQC ...
- 《手把手教你学C语言》学习笔记(7)---程序的输入与输出
程序设计中,为了观察程序的运行状态和结构,需要输出指定的内容:为了让程序能够更加灵活,可以根据需求输入内容,让计算机处理和运行:所以程序的输入输出就显的尤为重要.主要包括printf和scanf函数. ...
- linux内核情景分析之匿名管道
管道的机制由pipe()创建,由pipe()所建立的管道两端都在同一进程.所以必须在fork的配合下,才可以在具有亲缘关系的进程通信 /* * sys_pipe() is the normal C c ...
- SDOI2017round1酱油记day0
嗯... 现在是21:12...准备睡了. 睡前写下day0一天如何过的: 早上5点起床到教室早自习,迷迷糊糊的宣誓,背东西,英语听写: 都停课了为什么还要上早自习! 我!想!去!机!房! OI才是我 ...
- PHP二维数组排序研究
前几天在项目中碰到了一个问题,在做商城的时候,要对一个店铺里所有商品进行价格排序,而且每一种商品都拥有多个规格,要取到所有商品中所有规格的最低价和最高价,发现PHP有很友好的函数帮助我们进行筛选. 使 ...
- Codeforces Round #464 (Div. 2) B. Hamster Farm[盒子装仓鼠/余数]
B. Hamster Farm time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- ATOM入坑必备插件
Atom作为Javascript/CSS/HTML等前端编辑器利器,其强大功能依靠各种插件,以下是笔者在入坑阶段,精挑细选总结出的必不可少的插件,熟悉运用这些插件,一定成吨提高生产效率.安装这些插件只 ...
- Java Hibernate事务并发控制
在产品上线时发现当用户数量大并发性能差,经常发现数据库死锁,经诊断,是由于设置了不正确的事务隔离,可以做如下优级化(这里我们使用JTA事务): JTA具有的3个接口:UserTransaction接口 ...
- Codeforces Round #490 (Div. 3)
感觉现在\(div3\)的题目也不错啊? 或许是我变辣鸡了吧....... 代码戳这里 A. Mishka and Contes 从两边去掉所有\(≤k\)的数,统计剩余个数即可 B. Reversi ...