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. 命令操作MySQL数据库

    一.连接MYSQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1. 连接到本机上的MYSQL. 首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u roo ...

  2. iOS rebuild from bitcode对ipa大小的影响

    https://developer.apple.com/library/content/technotes/tn2432/_index.html 为了测试一下rebuild from bitcode的 ...

  3. RIDE的下载及安装

    1.本机配置 windows8.1 python3.6.5,已配置环境变量 2.安装RIDE前需要安装的依赖包(使用pip就可以直接安装) 首先必须有robotframework 例如:pip ins ...

  4. Python 八皇后问题

    八皇后问题描述:在一个8✖️8的棋盘上,任意摆放8个棋子,要求任意两个棋子不能在同一行,同一列,同一斜线上,问有多少种解法. 规则分析: 任意两个棋子不能在同一行比较好办,设置一个队列,队列里的每个元 ...

  5. 移动 ProgramData\Package Cache 文件夹

    装完vs2017 发现C盘快木有空间了… 瞅瞅C盘下有啥能删的好释放下空间 就找到了 Package Cache 文件夹,占用空间接近15G… 查查这个文件夹还不建议删除… (http://super ...

  6. 【原创】sqlite ef6 踩坑

    调试的时候配置写如下,这样写是没有问题的但是在实际环境中有问题,因为EF路径找不到.会提示错误:The underlying provider failed on open <connectio ...

  7. Linux系统下安装JDK

    注意:linux系统下使用mount命令挂载Windows系统下的共享文件,详情见我的另一篇“Linux系统挂载Windows系统下的共享文件” 一.安装jdk 1.进入usr目录cd /usr 2. ...

  8. Cpp Generals 1.2

    原文链接https://www.cnblogs.com/zhouzhendong/p/Cpp-Generals.html 源码暂不公开 下载链接 适用系统: Windows: 运行时请在进入彩色界面之 ...

  9. UOJ#201. 【CTSC2016】单调上升路径 构造

    原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ201.html 题解 首先把题目里面的提示抄过来: 结论:假设带权无向图 G 有 100 个节点 1000 ...

  10. mybatis代码生成器——MyBatis Generator

    1.maven依赖 a.加入依赖 <!-- mybatis生成工具 --> <dependency> <groupId>org.mybatis.generator& ...