AT_ndpc2026_d.Banknote
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the AtCoder Kingdom, banknotes of denominations 1 yen, 10 yen, 100 yen, …, 10100 yen are used.
Alice wants to pay N yen to Bob. Find the minimum possible total number of banknotes exchanged, which is the sum of:
- the number of banknotes Alice gives to Bob, and
- the number of banknotes Bob gives back as change.
More precisely, for any integer M≥N, consider:
- the minimum number of banknotes needed to represent exactly M yen, and
- the minimum number of banknotes needed to represent exactly M−N yen.
Find the minimum possible value of their sum.
You are given T test cases. Solve each of them.
在 AtCoder 王国,流通的纸币面额为 1 日元、10 日元、100 日元、…、10100 日元。
爱丽丝想向鲍勃支付 N 日元。求交换纸币的最小总张数,即:
- 爱丽丝付给鲍勃的纸币张数,加上
- 鲍勃找零给爱丽丝的纸币张数。
更准确地说,对任意整数 M≥N,考虑:
- 表示恰好 M 日元所需的最少纸币张数,以及
- 表示恰好 M−N 日元所需的最少纸币张数。
求上述两者之和的最小可能值。
你将得到 T 组测试数据,请分别求解每组数据。
输入格式
The input is given from standard input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例按以下格式给出:
N
输出格式
Print T lines. For the i-th line, output the answer for the i-th test case.
输出 T 行。对于第 i 行,输出第 i 个测试用例的答案。
输入输出样例
输入#1
3 7 34 123456789123456789
输出#1
4 7 44
说明/提示
Sample 1 Explanation:
In the first test case:
- Alice pays 10 yen using one 10-yen banknote, and
- Bob returns 3 yen as change using three 1-yen banknotes.
In this case, the total number of banknotes exchanged is 4, which is optimal.
Constraints
- 1≤T≤104
- 1≤N≤1018
- All input values are integers
样例 1 解释:
在第一个测试用例中:
- 爱丽丝使用一张 10 日元纸币支付 10 日元,且
- 鲍勃使用三张 1 日元纸币找零 3 日元。
此时,交换的纸币总数为 4 张,这是最优解。
约束条件
- 1≤T≤104
- 1≤N≤1018
- 所有输入值均为整数
输入解题思路,AI测评打分。不知道怎么写?