E. A Magic Lamp

Time Limit: 1000ms
Case Time Limit: 1000ms
Memory Limit: 32768KB
 
64-bit integer IO format: %I64d      Java class name: Main
 
 
Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question, and then the genie will realize one of her dreams. 
The question is: give you an integer, you are allowed to delete exactly m digits. The left digits will form a new integer. You should make it minimum.
You are not allowed to change the order of the digits. Now can you help Kiki to realize her dream?

 

Input

There are several test cases.
Each test case will contain an integer you are given (which may at most contains 1000 digits.) and the integer m (if the integer contains n digits, m will not bigger then n). The given integer will not contain leading zero.

 

Output

For each case, output the minimum result you can get in one line.
If the result contains leading zero, ignore it.

 

Sample Input

178543 4
1000001 1
100001 2
12345 2
54321 2
 

Sample Output

13
1
0
123
321
 
 解题:本来要RMQ做的,不明白啊!
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
char str[];
int main(){
int m,len,i,top;
while(scanf("%s %d",str,&m) == ){
len = strlen(str);
top = ;
for(i = ; i < len;){
if(m && top >= && str[top] > str[i]){m--;top--;}
else if(top != - || str[i] != '') str[++top] = str[i++];
else i++;
}
while(top >= && m){top--;m--;}
if(top == -) str[++top] = '';
str[++top] = '\0';
printf("%s\n",str);
}
return ;
}

E. A Magic Lamp的更多相关文章

  1. HDOJ 3183 A Magic Lamp

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. hdu 3183 A Magic Lamp(RMQ)

    题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...

  3. A Magic Lamp(贪心+链表)

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. hdu 3183 A Magic Lamp RMQ ST 坐标最小值

    hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...

  5. HDU 3183 - A Magic Lamp - [RMQ][ST算法]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...

  6. A Magic Lamp -- hdu -- 3183

    http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)   ...

  7. hdu 3183 A Magic Lamp(RMQ)

    A Magic Lamp                                                                               Time Limi ...

  8. hdu 3183 A Magic Lamp rmq或者暴力

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pro ...

  9. hdu A Magic Lamp

    http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)   ...

  10. HDU_3183_A Magic Lamp

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

随机推荐

  1. eCharts基础知识

    eCharts插件介绍 http://echarts.baidu.com/tutorial.html#ECharts%20%E7%89%B9%E6%80%A7%E4%BB%8B%E7%BB%8D

  2. AJPFX关于collection总结

    Collection接口是该层次结构的根接口,该接口的所有子接口或实现子类集合都可以用Iterator迭代器进行取出.Collection有两个常见子接口,即为List和Set,其中List集合可以用 ...

  3. codeforces727C(交互)

    题意 $n$个数,初始时不知道他们的值. 每次可以询问两个数的和,在$n$次询问内确定他们的值 $n \leqslant 5000$ Sol 首先询问出$1, 2$,$1, 3$,$2, 3$ 解个方 ...

  4. centos 7下Hadoop 2.7.2 伪分布式安装

    centos 7 下Hadoop 2.7.2 伪分布式安装,安装jdk,免密匙登录,配置mapreduce,配置YARN.详细步骤如下: 1.0 安装JDK 1.1 查看是否安装了openjdk [l ...

  5. 关于svn提交的时候强制写注释

    本文固定链接: http://www.linuxyan.com/linux-service/229.html 转载请注明: admin 2012年09月29日 于 ㄨ销声匿迹.Linux 发表 在sv ...

  6. 2017“编程之美”终章:AI之战勇者为王

    编者按:8月15日,第六届微软“编程之美”挑战赛在选手的火热比拼中圆满落下帷幕.“编程之美”挑战赛是由微软主办,面向高校学生开展的大型编程比赛.自2012年起,微软每年都在革新比赛命题.紧跟时代潮流, ...

  7. 51nod 1174 区间中最大的数(送盾题)

    基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出一个有N个数的序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,最大的数是多少. ...

  8. (四)mybatis之mybatis初了解

    前言:终于到mybatis啦!   Mybatis 前文有提到,Hibernate采用的是全表映射的方式,而这方式恰恰使得性能变得较差(https://www.cnblogs.com/NYfor201 ...

  9. SQLITE-更新查询

    SQLite -更新查询 SQLite UPDATE查询用于修改现有表中的记录.您可以使用WHERE子句与更新查询更新选中的行,否则会被更新的所有行. 语法: UPDATE查询的WHERE子句的基本语 ...

  10. Objective-C中的命名前缀说明

    http://www.cnblogs.com/dhui69/p/6410134.html __kindof __kindof 这修饰符还是很实用的,解决了一个长期以来的小痛点,拿原来的 UITable ...