102731: [AtCoder]ABC273 B - Broken Rounding
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Score : $200$ points
Problem Statement
Given a non-negative integer $X$, perform the following operation for $i=1,2,\dots,K$ in this order and find the resulting $X$.
- Round $X$ off to the nearest $10^i$.
- Formally, replace $X$ with $Y$ that is "the largest multiple of $10^i$ that minimizes $|Y-X|$."
- Here are some examples:
- Rounding $273$ off to the nearest $10^2$ yields $300$.
- Rounding $999$ off to the nearest $10^3$ yields $1000$.
- Rounding $100$ off to the nearest $10^{10}$ yields $0$.
- Rounding $1015$ off to the nearest $10^1$ yields $1020$.
Constraints
- $X$ and $K$ are integers.
- $0 \le X < 10^{15}$
- $1 \le K \le 15$
Input
The input is given from Standard Input in the following format:
$X$ $K$
Output
Print the answer as an integer.
Sample Input 1
2048 2
Sample Output 1
2100
$X$ changes as $2048 \rightarrow 2050 \rightarrow 2100$ by the operations.
Sample Input 2
1 15
Sample Output 2
0
Sample Input 3
999 3
Sample Output 3
1000
Sample Input 4
314159265358979 12
Sample Output 4
314000000000000
$X$ may not fit into a $32$-bit integer type.
Input
题意翻译
已知一个数字 $X$,依次进行 $K$ 次操作。 每次对数字 $X$ 按 $10^i$ 进行做 **四舍五入** 操作。 例: $273$ 按 $10^2$ 做四舍五入为 $300$ ; $273$ 按 $10^1$ 做四舍五入为 $270$。 请你求出,$K$ 次操作后,数字 $X$ 最终变为多少。 其中 $ 0 \leq X \leq 10^{15} $ $ 1 \leq K \leq 15 $ $ 1 \leq i \leq K $Output
分数:$200$分
问题描述
给定一个非负整数$X$,按照以下顺序对$i=1,2,\dots,K$进行以下操作,并找到最终的$X$。
- 将$X$四舍五入到最接近的$10^i$。
- 正式地说,将$X$替换为$Y$,$Y$是"最小化$|Y-X|$的$10^i$的倍数"。
- 以下是一些例子:
- 将$273$四舍五入到最接近的$10^2$得到$300$。
- 将$999$四舍五入到最接近的$10^3$得到$1000$。
- 将$100$四舍五入到最接近的$10^{10}$得到$0$。
- 将$1015$四舍五入到最接近的$10^1$得到$1020$。
约束条件
- $X$和$K$是整数。
- $0 \le X < 10^{15}$
- $1 \le K \le 15$
输入
输入以标准输入的以下格式给出:
$X$ $K$
输出
将答案作为整数打印。
样例输入 1
2048 2
样例输出 1
2100
通过操作,$X$变为$2048 \rightarrow 2050 \rightarrow 2100$。
样例输入 2
1 15
样例输出 2
0
样例输入 3
999 3
样例输出 3
1000
样例输入 4
314159265358979 12
样例输出 4
314000000000000
$X$可能不适合32位整数类型。