博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3183 A Magic Lamp
阅读量:6909 次
发布时间:2019-06-27

本文共 2183 字,大约阅读时间需要 7 分钟。

A Magic Lamp

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2947    Accepted Submission(s): 1149

Problem Description
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
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:            

 

 

题意:

题意:给出一个不超过1000位的数,求删去m个数字以后形成的最小的数是多少。

 

题解:

贪心,前面的数要小于后面的数,用栈维护

 

note:

注意前导0的去除

 

16573675 2016-03-16 19:08:20 Accepted 15MS 1732K 1882B C++

 

代码:

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 12 #define ll long long13 #define eps 1e-814 #define N 100415 #define inf 0x3ffffffffffffff16 17 using namespace std;18 19 char s[N];20 int m;21 int l;22 23 void solve()24 {25 stack
st;26 stack
ans;27 int i;28 for(i = 0;i < l;i++){29 while(!st.empty() && m > 0 && st.top()>s[i]){30 m--;31 st.pop();32 }33 if(m == 0) break;34 st.push(s[i]);35 }36 while(!st.empty() && m > 0){37 m--;38 st.pop();39 }40 //printf(" i=%d l =%d\n",i,l);41 int flag = 0;42 char te;43 while(!st.empty())44 {45 te = st.top();46 ans.push(te);47 st.pop();48 if(te != '0'){49 flag = 1;50 }51 }52 if(flag == 0){53 for(;i

 

转载于:https://www.cnblogs.com/njczy2010/p/5284758.html

你可能感兴趣的文章
链接详解--静态库
查看>>
从0开始学java——JUnit4 复习,其实基本思想还是那些,不过采用了新的注释格式的语法...
查看>>
lintcode:Length of Last Word 最后一个单词的长度
查看>>
GNU M4 - GNU Project - 免费软件基金会(FSF)
查看>>
OCP-1Z0-051-名称解析-文章7称号
查看>>
keepalived双BACKUP加nopreempt失效、手动监控服务脚步。
查看>>
form表单回车提交问题,JS监听回车事件
查看>>
ubuntu12.04 修改登陆用户 为root
查看>>
silverlight开发实例(Prism+MVVM+RIA)(二)--创建shell及用户登录
查看>>
jsp中将后台传递过来的json格式的list数据绑定到下拉菜单select
查看>>
Project Euler 85 :Counting rectangles 数长方形
查看>>
MYSQL查询某字段中以逗号分隔的字符串的方法
查看>>
Excel设置下拉菜单并隐藏下拉菜单来源单元格内容
查看>>
Java8初体验(二)Stream语法详解
查看>>
微服务架构——不是免费的午餐
查看>>
基于HTML5的Web SCADA工控移动应用
查看>>
VS 2015相当不错的功能:C#交互窗口
查看>>
hive复杂类型与java类型的对应
查看>>
[Ubuntu] ubuntu10.04系统维护之Wine的安装
查看>>
iOS获取UIView上某点的颜色值
查看>>