Educational Codeforces Round 116 (Rated for Div. 2)C. Banknotes

题意:In Berland, n different types of banknotes are used. Banknotes of the i-th type have denomination 10ai burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly 1.

Let’s denote f(s) as the minimum number of banknotes required to represent exactly s burles. For example, if the denominations of banknotes used in Berland are 1, 10 and 100, then f(59)=14: 9 banknotes with denomination of 1 burle and 5 banknotes with denomination of 10 burles can be used to represent exactly 9⋅1+5⋅10=59 burles, and there’s no way to do it with fewer banknotes.

For a given integer k, find the minimum positive number of burles s that cannot be represented with k or fewer banknotes (that is, f(s)>k).
Input
The first line contains a single integer t (1≤t≤104) — number of test cases.

The first line of each test case contains two integers n and k (1≤n≤10;1≤k≤109).

The next line contains n integers a1,a2,…,an (0=a1<a2<⋯<an≤9).
Output
For each test case, print one integer — the minimum positive number of burles s that cannot be represented with k or fewer banknotes.
主要意思就是给定n种钞票,每种钞票的面值都是10的ai次幂。给出你可以使用的钞票的个数m,问在m个钞票内(包括m),你得不到钞票总面值的最小值。
首先让m+1,第m+1张用最小面值。因为要求总面值的最小值,所以我们就从最小的面值开始加。因为个面值之间相差都是10的ai次幂,所以我们每种面值的钞票最多用c[i]=b[i]/b[i-1]-1张(b[i]表示面值,c[i[表示最多能用的个数),那就能多用就多用,先让sum+=b[i]*c[i](sum代表总面值)。一旦剩余的钞票数m小于当前面值钞票最多能用的张数,剩下的钞票数全用当前面值的钞票,sum+=(m+1)b[i]。这就是最大面值。
根据下面的代码更容易理解:

#include<bits/stdc++.h>
using namespace std;
long long n, k, a[101], b[101], c[101];
int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n>>k;
		for (int i=1;i<=n;i++){
			cin>>a[i];
			b[i]=pow(10, a[i]);//面值
			if (i==1)continue;
			c[i-1]=b[i]/b[i-1]-1;//最多用的个数
		}
		long long sum=0, i=1;
		while(k>=c[i] && i<n){
			k-=c[i];
			sum+=c[i]*b[i];
			i++;
		}
		sum+=(k+1)*b[i];
		cout<<sum<<endl;
	}
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值