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. 【经验之谈】前端面试知识点总结03(JavaScript相关)——附答案

    目录 三.JavaScript部分 1.谈谈你对Ajax的理解?(概念.特点.作用) 2.说说你对延迟对象deferred的理解? 3.什么是跨域,如何实现跨域访问? 4.为什么要使用模板引擎? 5. ...

  2. go语言 类型:数组

    在go语言中数组array是一组特定长度的有序的元素集合. go的数组类型由两部分组成——类型和长度,二者缺一不可.数组本来就是一块存储相同类型元素的连续内存空间,因此决定一个数组的类型,必然需要决定 ...

  3. css通用小笔记03——浏览器窗口变小 div错位的问题

    我最近写网页的时候,经常碰到一个普遍的问题,经过我的查阅和尝试,终于解决了这一问题,这里有两种方法提供给大家,如果博友还有更好的方法,欢迎补充. 一.使用min-width属性: 我们先看看下面这段代 ...

  4. C#遍历得到checkboxlist选中值和设置选中项

    得到选中项的value值并拼接成一个字符串返回 public string GetChecked(CheckBoxList checkList, string separator) { string ...

  5. tmtTable设计说明文档

    文件链接:tmt-table.js BOSS后台项目用到最多的就是列表页,所以把列表页做成通用组件,可以大大提高开发效率. 因为列表可能有不同的样式,所以在实例化组件时可以传值控制样式,用这种方式: ...

  6. ContentProvider实现流程

    个人记录 public class DataBaseContentProvider extends ContentProvider { private SQLiteOpenHelper mSQLite ...

  7. 图解Android触摸事件分发

    Android中触摸事件传递过程中最重要的是dispatchTouchEvent().onInterceptTouchEvent()和onTouchEvent()方法. View和Activity有d ...

  8. Android - ADB 的使用

    一.什么是ADB? 1.ADB全称Android Debug Bridge, 是android sdk里的一个工具,用这个工具可以直接操作管理android模拟器或者真实的andriod设备 2.AD ...

  9. IOS开发之小实例--创建一个简单的用于视频录制和回放的应用程序

    前言:还是看了一下国外的入门IOS文章:<Create a Simple App for Video Recording and Playback>,主要涉及视频录制和回放的功能的基本实现 ...

  10. NSString 字符串替换

    NSString * oneScale=@"@ddd"; NSLog(@"%@",[oneScale stringByReplacingOccurrencesO ...