Educational Codeforces Round 116 (Rated for Div. 2), problem: (C) Banknotes
题目

题目重点内容手打翻译:(欢迎批评指正)
在柏林, 使用着n套不同的货币(banknotes)。第i个货币面额为10ai 元,货币的第一种只能是1。定义f(s)为需要s元的最小货币数量,例如货币面额分别为1,10,100,然后f(59) = 14 :因为 九个面额1元的货币和五个面额10元的货币,也就是9*1+5*10=59元,并且没有办法使用更少的货币数量
思路
尽量选择小面值的, 还不能被其它货币代替的, 也就是10ai+1 - 10ai - 1, 题目样例很良心, 可以猜出来, 部分解释在代码里
AC代码
#include <iostream>
#include <algorithm> using namespace std; typedef long long LL;
const int N = 1e6;
LL money[15];
int a[20]; void init()
{
money[0] = 1;//money是10的i次方
for(int i = 1; i <= 10; i ++)
money[i] = money[i-1]*(LL)10;
}
int main(){
int t, n, k; init();
cin >> t;
while(t --)
{
cin >> n >>k;
k ++;//k是货币数量, +1因为最后要让他k个货币无法达到这些钱(res)
for(int i = 0; i < n; i ++) cin >> a[i]; sort(a, a+n); LL res = 0;
for(int i = 0; i < n; i ++)
{
if(i == n-1){//特判, 多写点这些就不用考虑最后了
res += (LL)k * money[a[i]];
break;
}
//chaju就是差距,比如1和10差9,1和100差99,代表本回合最多能加多少个a[i]
LL chaju = 0, tt = a[i+1]-a[i];
chaju = money[tt] - 1; if(k > chaju){
k -= chaju;
res += (LL)chaju * money[a[i]];
}
else{
res += (LL)k * money[a[i]];
break;
}
}
cout << res <<endl;
}
return 0;
}
Educational Codeforces Round 116 (Rated for Div. 2), problem: (C) Banknotes的更多相关文章
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
随机推荐
- 服务器中一个进程kill不掉,如何处理?
问题描述: 我们在服务器中有时候kill一个进程,会碰到死活杀不死的情况,那么有可能这个进程成为了一个僵尸进程,zombie状态.这种情况是这个进程释放了资源,但是没有得到父进程的确认. 可以使用命令 ...
- futter环境安装
镜像下载.域名解析.时间同步请点击 阿里巴巴开源镜像站 Flutter是谷歌开发的一款开源.免费的基于Dart语言的UI框架,可以快速在IOS和Android上构建高质量的原生应用.它的最大的特点是跨 ...
- 虚拟机Centos安装配置
开始吧~ 新建一个虚拟机 完成后编辑虚拟机 配置内存 处理器: 映像文件: 点击确定完成配置: 开启虚拟机,对操作系统进行配置 输入红线上内容,为计算机选择默认网卡 选择安装时的语言,可选择中文: 设 ...
- Python GUI tkinter 学习笔记(二)
第二个程序 # -*- coding: utf-8 -*- from Tkinter import * class App: def __init__(self, master): # frame 创 ...
- 使用 Mosh 来优化 SSH 连接
1.什么是Mosh Mosh表示移动Shell(Mobile Shell),是一个用于从客户端跨互联网连接远程服务器的命令行工具.它能用于SSH连接,但是比Secure Shell功能更多.它是一个类 ...
- 关于List、Set、Map接口讲解
概述 List.Set接口都是继承于Collection主接口,而Map为独立接口 1.List接口下有ArrayList.Vector.LinkedList实现类 2.Set接口下有HashSet. ...
- unittest 测试用例实现
unittest框架结构 test_case: 测试套件,每一个.py文件代表一个测试用例,测试用例以test开头,否则框架读取不到测试用例 __init__.py是做什么的? 要弄明白这个问题,首先 ...
- vue自定义指令?
除核心指令之外的指令, 使用directive进行注册. 指令自定义钩子函数: bind, inserted, update, componentUpdated, unbind
- vmware克隆Centos虚拟机网卡无法启动问题
快速处理办法: cat /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i '/UUID/d' /etc/sysconfig/network-script ...
- 学习Kvm(二)
一.走进云计算 云计算:云计算是一种按使用量付费的模式,这种模式提供可用的.便捷的.按需的网络访问, 进入可配置的计算资源共享池(资源包括网络,服务器,存储,应用软件,服务),这些资源能够被快速提供, ...