CF 2014 ACM-ICPC Vietnam National Second Round C. ATM withdrawal
2015-03-15 20:53
1911 查看
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
Output
解析
官方题解
我先把数据缩小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
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; }
相关文章推荐
- CF 2014 ACM-ICPC Vietnam National Second Round D. Treasure Box
- CF 2014 ACM-ICPC Vietnam National Second Round I. Space Tour
- 【分解质因数】【树状数组】【快速幂】codeforces 2014 ACM-ICPC Vietnam National Second Round E. ACM
- 2014 ACM-ICPC Vietnam National Second Round
- ACM ICPC Vietnam National Second Round
- ACM ICPC Vietnam National Second Round D X = X + X % 100
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- zoj 3809 The Himalayas 水题 The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round A
- zoj 3811 Untrusted Patrol 图论 The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- ZOJ 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round J
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The Himalayas --The 2014 ACM-ICPC Asia Mudanjiang Regional First Round - A
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round C ZOj 3811
- ZOJ 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round C ZOj 3811
- [CF Gym 100827C] Containment [2014-2015 ACM-ICPC Pacific Northwest Regional Contest C]
- 2014 ACM-ICPC Asia Mudanjiang Regional First Round