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. js当前日期

    function CurentTime()    {         var now = new Date();               var year = now.getFullYear(); ...

  2. Jenkins上svn更新策略说明

  3. 全站变灰的CSS代码-适合特殊时刻哀悼

    将下面CSS代码应用到HTML标签或者是BODY标签 filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.o ...

  4. itextsharp-5.2.1-修正无法签名大文件问题

    PDF文件格式几乎是所有开发平台或者业务系统都热爱的一种文档格式. 目前有很多优秀的开源PDF组件和类库.主要平时是使用.NET和Java开发,所以比较偏好使用iText,当然,它本身就很强大.iTe ...

  5. ubuntu 使用apt命令时报错 E: Could not get lock /var/lib/dpkg/lock - open...

    问题描述: 刚刚安装好Ubuntu16.04.使用apt命令时,提示报错信息: abc@pc:~$ sudo apt-get install openssh-server E: Could not g ...

  6. appium---AndroidSdk安装

    AndroidSDK指的是Android专属的软件开发工具包,被软件开发工程师用于为特定的软件包.软件框架.硬件平台.操作系统等建立应用软件的开发工具的集合.Android又是采用java语言进行开发 ...

  7. 《毛毛虫团队》第七次作业:团队项目设计完善&编码

    一:实验名称:团队项目设计完善&编码 二:实验目的与要求 掌握软件编码实现的工程要求. 三:实验步骤 任务一:团队软件项目设计完善: 任务二:团队软件项目编码实现: 任务三:在团队博客发布博文 ...

  8. luogu4608 [FJOI2016]所有公共子序列问题

    题目描述: luogu loj 题解: 序列自动机(?)+高精+普及dp. 这个是猫老师的序列自动机(字符串从1开始): ]) { memset(t[n],-,sizeof(t[n])); ;i> ...

  9. 转 Solr vs. Elasticsearch谁是开源搜索引擎王者

    转 https://www.cnblogs.com/xiaoqi/p/6545314.html Solr vs. Elasticsearch谁是开源搜索引擎王者 当前是云计算和数据快速增长的时代,今天 ...

  10. 笔记--Day1--python基础1

    一.目录 1.Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum),目前已经是使用频度特别高的开发语言. 主要应用领域: 云计算:云计算最火的语言,典型应用有Op ...