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. python(一)

    1 python安装 先安装python,之后安装pycharm 创建工程时需要关联解释器路径: 2 python运行 先编译后解释 .py--.pyc文件---解析----结果 .pyc的目的是减少 ...

  2. 【虚拟机-磁盘管理】理解及快速测定 Azure 虚拟机的磁盘性能

    随着越来越多的用户将生产系统迁移到 Azure 平台的虚拟机服务中,Azure 虚拟机的性能愈发被关注.传统的数据中心中,我们通常使用 CPU,内存,存储和网络的性能来衡量生产压力.特别是对于 IO ...

  3. .NET 读取视频文件

    该篇文章 复制别人的文章 在.NET中处理视频是一件痛苦的事情,.NET并没有提供视频处理的类.于是咱们只能找一些第三方的类库或者自己实现,在项目时间比较赶的情况下,自己实现是不可能的了,而且说不定会 ...

  4. Java VS Python 应该先学哪个?

    http://blog.segmentfault.com/hlcfan/1190000000361407 http://www.tuicool.com/articles/fqAzqi Java 和 P ...

  5. SAP C4C Opportunity和SAP ERP Sales流程的集成

    首先在C4C里创建一个新的Opportunity: 给这个Opportunity添加一个新的产品: 点按钮:Request Pricing, 从ERP抓取pricing数据,点按钮之前Negotiat ...

  6. cv2.Canny 边缘检测

    Canny边缘检测   Canny 的目标是找到一个最优的边缘检测算法,最优边缘检测的含义是: 好的检测 - 算法能够尽可能多地标识出图像中的实际边缘. 好的定位 - 标识出的边缘要尽可能与实际图像中 ...

  7. 爬虫遇到HTTP Error 403的问题

    # coding=gbk from bs4 import BeautifulSoup import requests import urllib x = 1 y = 1 def crawl(url): ...

  8. mini_httpd的安装和配置

    1.下载:http://www.acme.com/software/mini_httpd/mini_httpd-1.19.tar.gz 2.解压:tar zxvf mini_httpd-1.19.ta ...

  9. Bootstrap历练实例:标签页内的下拉菜单

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  10. 1_HDFS理论及安装部署

    一.hadoop简介 1.hadoop的初衷是为了解决Nutch的海量数据爬取和存储的需要,HDFS来源于google的GFS,MapReduce来源于Google的MapReduce,HBase来源 ...