C. Efim and Strange Grade
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The first line of the input contains two integers n and t (1 ≤ n ≤ 200 000, 1 ≤ t ≤ 109) — 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.

Output

Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.

Examples
input
6 1
10.245
output
10.25
input
6 2
10.245
output
10.3
input
3 100
9.2
output
9.2
Note

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.


题意:一个长度为n数,小数点后可以四舍五入t次,求最大可以是多少


终于填坑了,已经一个周了

一开始读错题,因为全部可以四舍五入。必须要学英语了

虽然没想到正解,写到一个贪心,每次从头往后找第一个可以进位的,然后就TLE了

正解竟然是DP,好神

d[i]表示i这一位进位最少需要几次,转移很简单了

最后进位时一定小心处理

//
// main.cpp
// cf#373cdp
//
// Created by Candy on 9/25/16.
// Copyright © 2016 Candy. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=2e5+,INF=1e9+;
int n,t,point=,l,high=;
char s[N];
int d[N];
void dp(){
d[n+]=INF;
for(int i=n;i>point;i--){
if(s[i]<'') d[i]=INF;
if(s[i]>='') d[i]=;
if(s[i]=='') d[i]=d[i+]+;
}
}
void carry(int p){//printf("c %d\n",p);
int flag=;
for(int i=p-;i>=;i--){
if(flag==) break;
if(s[i]=='.') continue;
if(s[i]=='') {s[i]=''; if(i>point) l=i-;else l=point-;}
else {s[i]++;flag=;break;}
}
if(flag) high=;
}
int main(int argc, const char * argv[]) {
scanf("%d%d%s",&n,&t,s+);l=n;
for(int i=;i<=n;i++) if(s[i]=='.'){point=i;break;}
dp();
for(int i=point+;i<=n;i++) if(d[i]<=t){carry(i);l=i-;break;}
if(high){
putchar('');
for(int i=;i<point;i++) putchar('');
}else{
for(int i=;i<=l-;i++) putchar(s[i]);
if(s[l]!='.') putchar(s[l]);
}
return ;
}

CF719C. Efim and Strange Grade[DP]的更多相关文章

  1. Efim and Strange Grade

    Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题

    C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...

  3. codeforces 719C. Efim and Strange Grade

    C. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input sta ...

  4. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade —— 贪心 + 字符串处理

    题目链接:http://codeforces.com/problemset/problem/719/C C. Efim and Strange Grade time limit per test 1 ...

  5. codeforces 373 A - Efim and Strange Grade(算数模拟)

    codeforces 373 A - Efim and Strange Grade(算数模拟) 原题:Efim and Strange Grade 题意:给出一个n位的实型数,你可以选择t次在任意位进 ...

  6. Codeforces 718A Efim and Strange Grade 程序分析

    Codeforces 718A Efim and Strange Grade 程序分析 jerry的程序 using namespace std; typedef long long ll; stri ...

  7. 【22.17%】【codeforces718B】 Efim and Strange Grade

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  8. CodeForces 718A Efim and Strange Grade (贪心)

    题意:给定一个浮点数,让你在时间 t 内,变成一个最大的数,操作只有把某个小数位进行四舍五入,每秒可进行一次. 析:贪心策略就是从小数点开始找第一个大于等于5的,然后进行四舍五入,完成后再看看是不是还 ...

  9. 【题解】Making The Grade(DP+结论)

    [题解]Making The Grade(DP+结论) VJ:Making the Grade HNOI-D2-T3 原题,禁赛三年. 或许是我做过的最简单的DP题了吧(一遍过是什么东西) 之前做过关 ...

随机推荐

  1. webkit中获取用户选择文本和编程设定选择文本

    一.需求背景 在 Android 应用中,内嵌一个 WebView,希望捕获用户点击事件,通过 javascript 判断用户点击的是否英文单词,如果是则将被点击单词发给应用做进一步处理,并实用 ja ...

  2. [deviceone开发]-do_Dialog的基本使用示例

    一.简介 我们平常使用do_Notification的alert或者confirm都是比较简单弹窗. 更为复杂和个性化的弹窗需要用到do_Dialog, 它可以弹出一个自定义的窗口,窗口里的内容是你自 ...

  3. 【ios】使用Block对POST异步操作的简单封装

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3409721.html 一般情况下的POST异步操作需要实现以下 ...

  4. Xcode8如何去除控制台多余的打印信息

    Xcode8如何去除控制台多余的打印信息 最近刚使用了Xcode8.遇到了一些问题,总结如下.希望对大家有所帮助. 一.如何去除控制台多余的打印信息. 方法:点击Product----Scheme-- ...

  5. Android 手机卫士--九宫格使用

    本文地址:http://www.cnblogs.com/wuyudong/p/5907736.html,转载请注明源地址. 采用GridView来实现,和ListView使用方式类似,列数(3列) 首 ...

  6. java url方法解释

    java 的url类中有很多get方法 以下是获取值的意义 // 首先先看一下wikipedia上关于url的一个描述 //Every HTTP URL conforms to the syntax ...

  7. 你真的了解UIControl吗?

    一:首先查看一下关于UIControl的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIControl : UIView //控件默认是启用的YES.是否要禁用 ...

  8. Java中的经典算法之选择排序(SelectionSort)

    Java中的经典算法之选择排序(SelectionSort) 神话丿小王子的博客主页 a) 原理:每一趟从待排序的记录中选出最小的元素,顺序放在已排好序的序列最后,直到全部记录排序完毕.也就是:每一趟 ...

  9. socket编程中客户端常用函数 以及简单实现

    1 常用函数 1.1   connect() int connect(int sockfd, const struct sockaddr *servaddr, socklen_taddrlen); 客 ...

  10. org.apache packages can't be resolved in Eclipse解决方案

    删除.m2仓库里面对应的jar包,重新Maven->update project