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. 【追寻javascript高手之路01】javascript参数知多少?

    前言 我最近在思考一个问题,我本身平时还是积累了不少东西,面试时候问的东西基本逃不出写的博客(当然,高级阶段的就不行了),但是真的被问到时我却不一定答得上来. 知道且能回答,回答的效果都不是很好... ...

  2. go语言条件语句 if else

    示例: if a < 5 { return 0 } else { return 1 } 关于条件语句,需要注意以下几点:  条件语句不需要使用括号将条件包含起来():  无论语句体内有几条语 ...

  3. 我们的动机(Our motivation)

    我们的动机(Our motivation) There are many PHP frameworks nowadays, but none of them is like Phalcon (Real ...

  4. CSS属性之float学习心得

    全文参考:http://www.linzenews.com/program/net/2331.html 我们来看看CSS重要属性--float. 以下内容分为如下小节: 1:float属性 2:flo ...

  5. ABAP--关于ABAP流程处理的一些命令的说明(stop,exit,return,check,reject)

    Stop 命令 使用该命令的程序位置 INITIALIZATION, AT SELECTION-SCREEN, START-OF-SELECTION和GET 事件中 处理说明 1. 当在INITIAL ...

  6. SharePoint 判断用户是否在字段"人员和组"里面

    两个自己平时写的方法,记录下来,方便以后查找使用: 1.判断用户是否在字段人员和组里面: public static bool IsUserInFiled(int UserID, string Lis ...

  7. Vault 不同版本的API的异同

    大家知道,Autodesk Vault 2014有几个版本,依次为( Basic, Workgroup, Professional),不同版本的功能不相同,关于Vault产品功能的不同之处可以在Vau ...

  8. Java中的引用类型(强引用、弱引用)和垃圾回收

    Java中的引用类型和垃圾回收 强引用Strong References 强引用是最常见的引用: 比如: StringBuffer buffer = new StringBuffer(); 创建了一个 ...

  9. git stash提交PR的正确步骤&git squash技术

    1.git stash梳理 1.1git stash的克隆与同步 首先整理下git stash的逻辑是这样 在本地做出了新的修改,提交时显示当前的版本不是最新版本,这时就需要先pull一下自己代码仓库 ...

  10. 优化MySchool数据库(存储过程)

    什么是“存储过程”: ---- 数据库中,用于存储“业务逻辑”的技术!(T-SQL代码当做数据一样保存到数据可) 语法 : [if exists(select * from sysobjects wh ...