是一道简单题

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

但是注意 数据类型声明 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. mysql多表查询20题

    +-------------------+| Tables_in_dapeng3 |+-------------------+| class || course || s1 || score || s ...

  2. postgresql 9.4.17 64位安装说明

    本文在win 7 64位下安装postgresql 9.4.17 64位版,安装过程有录入项的界面都有截图 运行安装程序开始安装 开始时可能自动安装c++运行环境 然后正式开始安装 安装目录位置,不要 ...

  3. Android 基础知识总结

    搞了这么久安卓开发,对基础的知识点总会遗忘,所有有必要总结一下:

  4. Java URL 中文乱码解决办法

    一. 统一所有的编码格式 (1)JSP页面设置:<%@ page language="java" import="java.util.*" pageEnc ...

  5. Spotlight安装

    刚才技术群的一个朋友在安装Spotligh出现了一些问题,所以本人临时写个简单的教程 1.下载安装包(安装包地址:https://pan.baidu.com/s/1c2tmqyc),解压,然后傻瓜式安 ...

  6. codevs 1519 过路费

    时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master 题目描述 Description 在某个遥远的国家里,有 n个城市.编号为 1,2,3,…,n.这个国家的政府 ...

  7. Git理论知识补充

    转自: http://www.cnblogs.com/hnrainll/archive/2012/11/13/2768003.html 对于任何一个文件,在 Git 内都只有三种状态:已提交(comm ...

  8. oracle补丁类型

    名称 说明 Release ¤ 标准产品发布.如Oracle Database 10g Release 2的第一个发行版本为10.2.0.1,可以在OTN.edelivery等站点上公开下载 Patc ...

  9. scriptPubKey and scriptSig

    First of all two matching scripts are used in two different transactions, one that transfers funds t ...

  10. matlab 随笔

    <<matlab高级编程技巧与应用:45个案例分析>> 一. 重新认识向量化编程 1.向量化编程与循环的比较 2.预分配内存更好 3.matlab中是列优先 4.归一化 数据归 ...