A10652 | Efim and Strange Grade
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are $t$ seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than $t$ seconds. Note, that he can choose to not use all $t$ seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the $n$ -th digit one has to take a look at the digit $n+1$ . If it is less than $5$ than the $n$ -th digit remain unchanged while all subsequent digits are replaced with $0$ . Otherwise, if the $n+1$ digit is greater or equal to $5$ , the digit at the position $n$ is increased by $1$ (this might also change some other digits, if this one was equal to $9$ ) and all subsequent digits are replaced with $0$ . At the end, all trailing zeroes are thrown away.
For example, if the number $1.14$ is rounded to the first decimal place, the result is $1.1$ , while if we round $1.5$ to the nearest integer, the result is $2$ . Rounding number $1.299996121$ in the fifth decimal place will result in number $1.3$ .
There are $t$ seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than $t$ seconds. Note, that he can choose to not use all $t$ seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the $n$ -th digit one has to take a look at the digit $n+1$ . If it is less than $5$ than the $n$ -th digit remain unchanged while all subsequent digits are replaced with $0$ . Otherwise, if the $n+1$ digit is greater or equal to $5$ , the digit at the position $n$ is increased by $1$ (this might also change some other digits, if this one was equal to $9$ ) and all subsequent digits are replaced with $0$ . At the end, all trailing zeroes are thrown away.
For example, if the number $1.14$ is rounded to the first decimal place, the result is $1.1$ , while if we round $1.5$ to the nearest integer, the result is $2$ . Rounding number $1.299996121$ in the fifth decimal place will result in number $1.3$ .
输入格式
The first line of the input contains two integers $n$ and $t$ ( $1<=n<=200000$ , $1<=t<=10^{9}$ ) — the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with $0$ .
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with $0$ .
输出格式
Print the maximum grade that Efim can get in $t$ seconds. Do not print trailing zeroes.
输入输出样例
输入 #1
6 1 10.245
输出 #1
10.25
输入 #2
6 2 10.245
输出 #2
10.3
输入 #3
3 100 9.2
输出 #3
9.2
In the first two samples Efim initially has grade $10.245$ .
During the first second Efim can obtain grade $10.25$ , and then $10.3$ during the next second. Note, that the answer $10.30$ will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
During the first second Efim can obtain grade $10.25$ , and then $10.3$ during the next second. Note, that the answer $10.30$ will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted