4493: Remove Digits

Description

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

Input

The first line has two integers N and K (N不大于500000). 
The next line has a N-digit number with no leading zero.

Output

Output the largest possible integers by removing K digits.

Sample Input 
4 2 
2835 
Sample Output 
85

在一个字符串里找到n-k位的递减数列or前几位递减,一直超时。。。

贪心用栈实现就好的
#include <stdio.h>
char s[];
int main()
{
int n,k,i,j,f=;
s[]=;
scanf("%d%d",&n,&k);
getchar();
for(i=; i<n; i++)
{
char c;
c=getchar();
while(c>s[f])
{
if(!k||!f)break;
k--;
f--;
}
s[++f]=c;
}
f-=k;
s[++f]=;
printf("%s",s+);
return ;
}

TOJ 4493 Remove Digits 贪心的更多相关文章

  1. TZOJ 4493: Remove Digits

    4493: Remove Digits 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 总提交: 329            测试通过:77 描述 G ...

  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. uva 993 Product of digits (贪心 + 分解因子)

      Product of digits  For a given non-negative integer number N , find the minimal natural Q such tha ...

  4. Codeforces 509C Sums of Digits 贪心

    这道题目有人用DFS.有人用DP 我觉得还是最简单的贪心解决也是不错的选择. Ok,不废话了,这道题目的意思就是 原先存在一个严格递增的Arrary_A,然后Array_A[i] 的每位之和为Arra ...

  5. Codeforces Round #667 (Div. 3) D. Decrease the Sum of Digits (贪心)

    题意:给你一个正整数\(n\),每次可以对\(n\)加一,问最少操作多少次是的\(n\)的所有位数之和不大于\(s\). 题解:\(n\)的某个位置上的数进位,意味这后面的位置都可以被更新为\(0\) ...

  6. (Problem 37)Truncatable primes

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

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

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

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

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

  9. 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 ...

随机推荐

  1. 掌握 Azure 的注册、帐户和订阅管理 Azure 上云须知

    计划使用由世纪互联运营的 Microsoft Azure 的用户,可通过下列流程注册开通并购买所需 Azure 服务:信息获取 > 试用 > 购买 > 账户/订阅管理 > 支付 ...

  2. GoAccess安装和使用介绍

    使用文档参考地址:https://my.oschina.net/mrco/blog/181737https://www.fanhaobai.com/2017/06/go-access.html goa ...

  3. vue分环境打包配置不同命令

    1.安装cross-env (cross-env能跨平台地设置及使用环境变量)cnpm/npm  i  cross-env -D 2.新建模板 红色的为相关文件 3.配置各个文件 (1)config下 ...

  4. HDU 1850 Being a Good Boy in Spring Festival 在春节做乖孩子(Nim博弈,微变形)

    题意: 思路: 如果全部扑克牌数目异或的结果ans为0,则必输,输出0.否则,必须要给对方一个P状态,可以对所有扑克堆进行逐个排查,将ans^a[i]就可以得到除了a[i]之外其他扑克数的异或结果tm ...

  5. SAP OData编程指南

    OData(Open Data Protocol)协议是一个开放的工业标准,用于定义RESTFul API的设计和使用.我的文章标题前加上SAP的前缀,只是为了表明这篇文章介绍的是Jerry在SAP项 ...

  6. OO作业第二单元总结

    目录 一.设计策略 1 2 3 二.程序分析 1 2 3 S.O.L.I.D分析 三.Bug分析 1 2 3 四.互测策略 五.心得体会 一.设计策略 1 第一次完成的是一个傻瓜电梯,简单来说,就是来 ...

  7. Python——序列封包与序列解包

    一.序列封包与序列解包 把多个值赋给一个变量时,Python会自动的把多个值封装成元组,称为序列封包. 把一个序列(列表.元组.字符串等)直接赋给多个变量,此时会把序列中的各个元素依次赋值给每个变量, ...

  8. 03_6_package和import语句

    03_6_package和import语句 1. package和import语句 为便于管理大型软件系统中数目众多的类,解决类的命名冲突问题,Java引入包(package)机制,提供类的多重命名空 ...

  9. C# 用qq邮箱发邮件

    一.在企业的QQ邮箱中开启POP3/SMTP服务 开启服务时,授权密码保存好. 二.示例 public static string UserName = ""; // 企业邮箱 p ...

  10. Git下的gitignore规则介绍

    匹配模式前/代表项目根目录 匹配模式最后加/代表是目录 匹配模式前加!代表取反 (忽略文件夹,但不忽略文件夹下的某个文件) *代表任意个字符 ? 匹配任意一个字符 **匹配多级目录 node_modu ...