是一道简单题

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

但是注意 数据类型声明 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. AJPFX总结线程创建的两种方法

    创建线程的第一种方式:继承Thread ,由子类复写run方法.步骤:1,定义类继承Thread类:2,目的是复写run方法,将要让线程运行的代码都存储到run方法中:3,通过创建Thread类的子类 ...

  2. 关于HashMap中hash()函数的思考

    关于HashMap中hash()函数的思考 JDK7中hash函数的实现   static int hash(int h) { h ^= (h >>> 20) ^ (h >&g ...

  3. re正则表达式公式讲解4

    1.re,split()  字符串分离 import re s = "abc20tyu9iou16hij25" m = re.split("\d",s) #以& ...

  4. spark性能优化-JVM虚拟机垃圾回收调优

    1 2 3 4

  5. Scala基础篇-05求值策略

    Scala的求值策略有2种: call by value call by name 如何区分? 例子: def bar(x:Int,y: => Int) = def loop(): Int=lo ...

  6. mongodb多条件查询总结

    根据两字段乘积过滤查询分页数据 db.cron.aggregate([{$project:{_id:,AppID:,result:{$add:["$endlottery",&quo ...

  7. JS实现让其他浏览器自动转至微信浏览器打开链接

    //判断是否是pc function is_pc() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUser ...

  8. Linux/Windows 实用工具简记

    以下只是开发中可能用的比较多的工具,另外还有其他很多未曾提及的实用工具.Linux篇: 1.链接过程的调试:主要用于查看构建过程:如链接时加载的动态库以及运行时加载动态库过程的调试 支持LD_DEBU ...

  9. Qt 为QPushButton、QLabel添加鼠标移入移出事件

    QT 为QPushButton.QLabel添加鼠标移入移出事件**要实现的效果:**鼠标移入QPushButton时与移出时按钮变换字体颜色,鼠标移入QLabel时显示上面的文字,移出时不显示.** ...

  10. gitlab利用ssh方式拉取代码

    问题1: Bad owner or permissions on .ssh/config的解决 当为本机配一个固定用户名远程登录某主机时,配置了一个config文件,但是在执行ssh免密码登录时报如下 ...