4493: Remove Digits

时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte
总提交:
329
          
测试通过:77

描述

Given an N-digit number, you should remove K digits and make the new integer as large as possible.

输入

The first line has two integers N and K (1 ≤ K<N≤500000).
The next line has a N-digit number with no leading zero.

输出

Output the largest possible integers by removing K digits.

样例输入

4 2
2835

样例输出

85

 #include <bits/stdc++.h>
using namespace std;
char s[];
int main()
{
ios::sync_with_stdio(false);
int n,k,num=;
char c;
s[]='';
cin>>n>>k;
for(int i=;i<n;i++){
cin>>c;
while(c>s[num]){
if(!k||!num) break;
num--,k--;
}
s[++num]=c;
}
if(k)
num=num-k;
s[++num]='\0';
cout << s+ << endl;
return ;
}

TZOJ 4493: Remove Digits的更多相关文章

  1. TOJ 4493 Remove Digits 贪心

    4493: Remove Digits Description Given an N-digit number, you should remove K digits and make the new ...

  2. 【TOJ 4493】Remove Digits(单调栈贪心)

    描述 Given an N-digit number, you should remove K digits and make the new integer as large as possible ...

  3. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  4. codeforces 887A Div. 64 思维 模拟

    A. Div. 64 time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. kettle--组件(2)--计算器

    组件如下: 对计算类型的说明如下: The table below contains descriptions associated with the calculator step: Functio ...

  6. Codeforces Round #444 (Div. 2)A. Div. 64【进制思维】

    A. Div. 64 time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  7. Project Euler:Problem 37 Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  8. [LeetCode] Remove K Digits 去掉K位数字

    Given a non-negative integer num represented as a string, remove k digits from the number so that th ...

  9. leetcode 402. Remove K Digits

    Given a non-negative integer num represented as a string, remove k digits from the number so that th ...

随机推荐

  1. 【剑指offer】【python】面试题2~5

    使用python实现<剑指offer>面试题ヾ(◍°∇°◍)ノ゙,以此记录. 2_实现Singleton模式 题目:实现单例模式 单例模式,是一种常用的软件设计模式.在它的核心结构中只包含 ...

  2. noj算法 堡垒问题 回溯法

    描述: 城堡是一个4×4的方格,为了保卫城堡,现需要在某些格子里修建一些堡垒.城堡中的某些格子是墙,其余格子都是空格,堡垒只能建在空格里,每个堡垒都可以向上下左右四个方向射击,如果两个堡垒在同一行或同 ...

  3. file_get_contents函数偶尔报错的抑制显示

    $result = @file_get_contents($url);可以使用@进行抑制file_get_contents()的报错 @是为了抑制错误显示,让用户看不到,提升用户体验.注意:只是抑制错 ...

  4. Main Thread Checker 问题解决

    1. without a return value https://developer.apple.com/documentation/code_diagnostics/main_thread_che ...

  5. Python学习计划

    ---恢复内容开始--- Python学习计划   https://edu.csdn.net/topic/python2?utm_source=blog4   匠人之心,成就真正Python全栈工程师 ...

  6. Maven mvn install 本地jar添加到本地maven仓库中

    mvn install:install-file -DgroupId=alipay -DartifactId=taobao-sdk-java-auto -Dversion=1.0 -Dpackagin ...

  7. P1516 青蛙的约会

    P1516 青蛙的约会x+mt-p1L=y+nt-p2L(m-n)t+L(p2-p1)=y-x令p=p2-p1(m-n)t+Lp=y-x然后套扩欧就完事了 #include<iostream&g ...

  8. 第三篇 request篇

    每个框架中都有处理请求的机制(request),但是每个框架的处理方式和机制是不同的 为了了解Flask的request中都有什么东西,首先我们要写一个前后端的交互 基于HTML + Flask 写一 ...

  9. PostgreSQL自学笔记:与python交互

    与python交互教程 原文地址:https://www.yiibai.com/html/postgresql/2013/080998.html 1. Python psycopg2 模块APIs 连 ...

  10. CSS(六)

    CSS权重 CSS权重指的是样式的优先级,有两条或多条样式作用于一个元素,权重高的那条样式对元素起作用,权重相同的,后写的样式会覆盖前面写的样式. 权重的等级 可以把样式的应用方式分为几个等级,按照等 ...