C. Banknotes(纸币)

传送门

题意:

给你长度为n的数组,数组的每个元素表示你有无数张面值为10^{a_i}的纸币,然后给你一个整数k,问在k张纸币中你不能组成的最小的钱是多少?

思路:

因为是不能组成的钱,那么+1张就是可以组成的钱,然后要使他最小。

贪心的说,如果要让组成的钱越少,那么小面额的纸币就要尽可能的多拿,那能拿到多少张呢?

假设你有10元和100元的纸币,那么你最多只能拿9张10元的,因为再多拿一张就可以变成100元的纸币:同样,如果你没有100的纸币但是你有1000的,那么你可以拿99张10元的纸币。

那么我们可以遍历一遍我们的数组,每次去遍历我们能拿的最大的纸币的数量,然后最后如果我们的纸币还有多的就一直拿最大的纸币就好了。

代码:

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
#define int long long 
using namespace std;

const int N = 200010, mod=1e9 + 7;
int T, n, m, a[N];

signed main(){
	
	
	cin>>T;
	while(T--)
	{
		cin>>n>>m;
		for(int i=1;i<=n;i++) cin>>a[i];
		
		int ans=0;
		m++;
		for(int i=1;i<n;i++)
		{
			ll x=pow(10,a[i]),y=pow(10,a[i+1]);
			int t=y/x-1;//当前纸币能拿的最大数量
			
			if(t<=m){
				ans+=t*x;
				m-=t;
			}
			else{
				ans+=m*x;
				m=0;
				break;
			}
		}
		if(m) ans+=m*(ll)pow(10,a[n]);
		
		cout<<ans<<endl;
	}
	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值