hdu 3183 A Magic Lamp rmq或者暴力
2016-04-13 19:54
330 查看
A Magic Lamp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each case, output the minimum result you can get in one line.
If the result contains leading zero, ignore it.
[align=left]Sample Input[/align]
178543 4
1000001 1
100001 2
12345 2
54321 2
[align=left]Sample Output[/align]
13
1
0
123
321
[align=left]Source[/align]
HDU 2009-11 Programming Contest
题意:给你一个数,在1000位内(字符串),删掉m个数,得到最小的数输出;
rmq :思路:第一位在len-m内;找到第n位以后,最后留下没有找数的数目(len-m-n),在n之后的区间找n+1;(0ms)
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define ll long long #define mod 1000000007 #define inf 999999999 int scan() { int res = 0 , ch ; while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) ) { if( ch == EOF ) return 1 << 30 ; } res = ch - '0' ; while( ( ch = getchar() ) >= '0' && ch <= '9' ) res = res * 10 + ( ch - '0' ) ; return res ; } vector<int>v; char a[1010]; int main() { int x,y,z,i,t; while(~scanf("%s%d",a,&x)) { v.clear(); int len=strlen(a); for(i=0; i<len; i++) v.push_back(a[i]-'0'); while(x--) { int flag=1; int len=v.size(); for(i=0; i<len-1; i++) { if(v[i]>v[i+1]) { flag=0; v.erase(v.begin()+i); break; } } if(flag) v.erase(v.begin()+len-1); } for(i=0; i<v.size(); i++) if(v[i]) break; for(t=i; t<v.size(); t++) printf("%d",v[t]); if(i==v.size()) printf("0"); printf("\n"); } return 0; }
View Code
相关文章推荐
- hdu 5179 beautiful number
- 我所了解的java单例模式
- rope大法好
- OpenMedia: 下一代免费的视频编解码器
- setw()使用方法
- mac下SVN服务器命令行
- SpringMVC三大设计原则
- Android客户端性能优化(魅族资深工程师毫无保留奉献)
- 如何取出一个整数的每位数字
- Redis+linux入门(二)
- Web开发过程中乱码问题
- 第四篇:R语言数据可视化之折线图、堆积图、堆积面积图
- HTML: vertical algin Big/small div in same row (bootstrap)
- 产品经理的职责有哪些?到底该做什么?
- Bootstrap学习笔记—关于列表组与多媒体对象
- [bzoj3673]可持久化并查集
- 欢迎使用Markdown编辑器写博客
- matlab 错误使用*
- 数据库范式
- centos中pppoe每次重新启动都要设置的问题