CodeForces - 462B Appleman and Card Game
是一道简单题
将字母从个数多到小排序 然后 再按题目算法得到最多
但是注意 数据类型声明 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的更多相关文章
- CodeForces 462B Appleman and Card Game(贪心)
题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase ...
- Codeforces 263B. Appleman and Card Game
B. Appleman and Card Game time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces 461B Appleman and Tree(木dp)
题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k ...
- codeforces 462C Appleman and Toastman 解题报告
题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...
- 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 ...
- Codeforces 461B. Appleman and Tree[树形DP 方案数]
B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 461B Appleman and Tree
http://codeforces.com/problemset/problem/461/B 思路:dp,dp[i][0]代表这个联通块没有黑点的方案数,dp[i][1]代表有一个黑点的方案数 转移: ...
- CodeForces 461B Appleman and T
题目链接:http://codeforces.com/contest/461/problem/B 题目大意: 给定一课树,树上的节点有黑的也有白的,有这样一种分割树的方案,分割后每个子图只含有一个黑色 ...
- Codeforces 461B Appleman and Tree:Tree dp
题目链接:http://codeforces.com/problemset/problem/461/B 题意: 给你一棵树(编号从0到n-1,0为根节点),每个节点有黑白两种颜色,其中黑色节点有k+1 ...
随机推荐
- spring mvc 解决 Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml] 异常
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document fro ...
- anzhuaggeoip
1.因启动geoip模块,需要先安装GeoIP # wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz # tar xv ...
- AIX 11203 ASM RAC安装
1:查看系统版本 [rac1:root:/hacmp/hacmp5.4/ha5.4/installp/ppc] oslevel -s 6100-06-06-1140 lslpp -al bos.adt ...
- docker环境安装
centos7安装docker环境 # step 1: 安装必要的一些系统工具 yum install -y yum-utils device-mapper-persistent-data lvm2 ...
- 用list去初始化numpy的array数组 numpy的array和python中自带的list之间相互转化
http://blog.csdn.net/baiyu9821179/article/details/53365476 a=([3.234,34,3.777,6.33]) a为python的list类型 ...
- QT_2
1.默认生成代码的含义(.pro)
- PHP12 文件操作
学习要点 文件系统概述 目录基本操作 文件基本操作 文件上传下载 文件上传类的设计 文件系统概述 概述 PHP文件系统的操作是基于UNIX系统模型,所以有一些文件处理函数无法在windows服 ...
- JavaEE-08 JSTL和EL
学习要点 EL表达式 JSTL标签 EL表达式 为什么需要EL表达式 JavaBean在JSP中的局限 在JSP页面中嵌入大量的Java代码 获取JavaBean属性必须要实例化 强制类型转化 例如, ...
- sed替换字符串中的某些字符
test.txt原文内容 http://jsldfjaslfjsldfjasl/test?jlsdfjsalfjslfd 使用sed替换 sed -ri 's/(http:\/\/)[^\/]*(\/ ...
- mongdb查询数据并且返回数据条数
var totall; var a = db.db("Magiccat").collection("jishi_content").find().count({ ...