是一道简单题

将字母从个数多到小排序 然后 再按题目算法得到最多

但是注意 数据类型声明 money要为long long

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int num[];
long long money[];//因为 虽然 n是到10^5但是有money和money相乘 的操作 再存储在同一位置 就超了
int n, k; bool cmp(int a, int b)
{
return a > b;
}
int main()
{
double sum = ;
freopen("in.txt", "r", stdin);
while (~scanf("%d%d", &n, &k))
{
getchar();
sum = ;
memset(num, , sizeof(num));
for (int i = ; i < n; i++)
{
char temp;
scanf("%c", &temp);
num[temp-'A']++;
}
sort(num, num+, cmp);
for (int i = ; i < ; i++)
{
money[i] = min(num[i], k);
k -= num[i];
if (k <= ) break;
}
for (int i = ; i < ; i++)
{
sum+= money[i]*money[i];
}
printf("%.0lf\n", sum);
}
return ; }

CodeForces - 462B Appleman and Card Game的更多相关文章

  1. CodeForces 462B Appleman and Card Game(贪心)

    题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase ...

  2. Codeforces 263B. Appleman and Card Game

    B. Appleman and Card Game time limit per test  1 second memory limit per test  256 megabytes input  ...

  3. Codeforces 461B Appleman and Tree(木dp)

    题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k ...

  4. codeforces 462C Appleman and Toastman 解题报告

    题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...

  5. Codeforces 388C Fox and Card Game (贪心博弈)

    Codeforces Round #228 (Div. 1) 题目链接:C. Fox and Card Game Fox Ciel is playing a card game with her fr ...

  6. Codeforces 461B. Appleman and Tree[树形DP 方案数]

    B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Codeforces 461B Appleman and Tree

    http://codeforces.com/problemset/problem/461/B 思路:dp,dp[i][0]代表这个联通块没有黑点的方案数,dp[i][1]代表有一个黑点的方案数 转移: ...

  8. CodeForces 461B Appleman and T

    题目链接:http://codeforces.com/contest/461/problem/B 题目大意: 给定一课树,树上的节点有黑的也有白的,有这样一种分割树的方案,分割后每个子图只含有一个黑色 ...

  9. Codeforces 461B Appleman and Tree:Tree dp

    题目链接:http://codeforces.com/problemset/problem/461/B 题意: 给你一棵树(编号从0到n-1,0为根节点),每个节点有黑白两种颜色,其中黑色节点有k+1 ...

随机推荐

  1. javascript 找出数字数组中最大的数

    找出数字数组中最大的数 var Match = (function(){ var arr = null; var len = 0; return { max:function(arr,len){ ar ...

  2. android studio MQTT测试成功

    package myself.mqtt.wenzheng.studio.mqtt; import android.app.Notification; import android.app.Notifi ...

  3. TFS强制删除离职人员签出锁定项的方法(转)

      项目组一哥们走的时候以独占方式迁出了文件,现在其他人都无法修改,管理员似乎也无法将文件解除.经过摸索,找到了一种暴力的方法——直接改TFS数据库.虽然暴力,却能实实在在地解决这个问题. 步骤: 1 ...

  4. 51nod 1417 天堂里的游戏

    基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 多年后,每当Noder看到吉普赛人,就会想起那个遥远的下午. Noder躺在草地上漫无目的的张望,二 ...

  5. 为什么要使用spl_autoload_unregister

    最近学习 laravel 源码,发现他的 autoload_real.php 里面有一段: spl_autoload_register(array('ComposerAutoloaderInit290 ...

  6. 判断请求是否为ajax

    判断请求是否为ajax 转载:http://www.cnblogs.com/tony-jingzhou/archive/2012/07/30/2615612.html x-requested-with ...

  7. 【转】关于编写WPF UserControl时提示The name 'InitializeComponent' does not exist in the current contextr的解决!

    1.打开.csproj(工程)文件. 2.找到<Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" /&g ...

  8. ZOJ3228 Searching the String (AC自动机)

    Searching the String Time Limit: 7 Seconds                                      Memory Limit: 129872 ...

  9. css3新增属性:多列(column)

    css3多列能够创建多个列来对文本进行布局,就想报纸那样. 关于多列的相关属性及属性值如下: column-count: number|auto;:指定元素应分为的列数.column-fill: 指定 ...

  10. 苹果平台上的媒体流播放技术HLS

    近日在和朋友聊起媒体流的服务器端实时转码技术的时候,发现苹果的各种终端上的视频播放并未使用常见的基于UDP的RTSP/RTP,而强制使用了Http Live Stream技术,这里稍稍总结了如下. 苹 ...