CF 2014 ACM-ICPC Vietnam National Second Round C. ATM withdrawal

C. ATM withdrawal
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vinh works for an ATM machine manufacturing company. The basic functionality of an ATM machine is cash withdrawal. When a user requests a cash withdrawal ofW VND (Vietnamese Dong), the ATM has to dispenseN money notes such that they sum up to W. For the next generation of ATM machine, Vinh is working on an algorithm to minimize the numberN of money notes for each cash withdrawal transaction.

Your task is to help Vinh to do his job given that the money notes come in the values of1000, 2000, 3000, 5000, 1000 * 101, 2000 * 101, 3000 * 101, 5000 * 101, ..., 1000 * 10c, 2000 * 10c, 3000 * 10c, 5000 * 10c where c is a positive integer and Vinh has unlimited supply of money notes for each value.

Input

The input file consists of several datasets. The first line of the input file contains the number of datasets which is a positive integer and is not greater than1000. The following lines describe the datasets.

  • The first line consists of one positive integer W(W ≤ 1018);
  • The second line consists of one positive integer c(c ≤ 15).
Output

For each dataset, write in one line two space-separated integers N and S where S is the number of ways to dispense the fewest number N of money notes. In case there is no way to serve the cash withdrawal request, write out 0 in one line instead.

Sample test(s)
Input
2
1000
1
7000
1
Output
1 1
2 1

解析

官方题解

我先把数据缩小1000倍。主要是要处理一个问题:如果你只有1,2,3,5要凑k元,打个表就有规律了。

k      1 2 3 4 5   6 7 8 9 10   11 12 13 14 15
note1 1 1 2 1   2 2 2  3  2     3   3    3   3   3
way 1 1 1 2 1   2 1 1 3  1      2   1   1    3   1

#include<cstdio>
#include<cstring>
using namespace std;

typedef long long LL;
#define INF 0x3f3f3f3f
LL kind[]={1,2,3,5},
   way[]={1,1,1,1,2,1,2,1,1,3, 1,2},
   note[]={0,1,1,1,2,1,2,2,2,3, 2,3};
LL W,C;
void find(LL x,LL &ans_note,LL &ans_way)
{
	LL Note=INF,Way=1;
	Note=(x-1)/5+1;if(x%5==4) Note++,Way=3;
	if(x%5==1) Way=2;
	if(x==1) Way=1; if(x==4) Way=2;
	ans_note=Note; ans_way=Way;
}
void work()
{
	LL ans_way=1,ans_note=0;
	for(int i=0;i<C && W>0;i++)
	{
		int dig=W%10;
		ans_way*=way[dig];
		ans_note+=note[dig];
		W=W/10;
	}
	if(W) {LL x,y;find(W,x,y);ans_note+=x;ans_way*=y;}
	printf("%I64d %I64d\n",ans_note,ans_way);
}

int main()
{
	int T; scanf("%d",&T);
	for(int i=1;i<=T;i++)
	{
		scanf("%I64d%I64d",&W,&C);
		if(W%1000) puts("0");
		else
			{
				W=W/1000;
				work();
			}
	}
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值