HDU_3183_A Magic Lamp
A Magic Lamp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4694 Accepted Submission(s): 1947
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?
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.
If the result contains leading zero, ignore it.
1000001 1
100001 2
12345 2
54321 2
1
0
123
321
- 长度为n的数串去掉m个数问剩下的数的最小值是多少
- 等价于求长度为n的数挑(n-m)个数使得其值最小
- 那么我们只要从高位开始每次挑选最小数一共挑(n-m)个就是结果
- 用ST表计算区间min
- 注意前导零的处理
- #include <iostream>
- #include <string>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <climits>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <set>
- #include <map>
- using namespace std;
- typedef long long LL ;
- typedef unsigned long long ULL ;
- const int maxn = 1e3 + ;
- const int inf = 0x3f3f3f3f ;
- const int npos = - ;
- const int mod = 1e9 + ;
- const int mxx = + ;
- const double eps = 1e- ;
- const double PI = acos(-1.0) ;
- int n, m, fac[], dp[maxn][], l, r, p, ans[maxn], tot, rec;
- char str[maxn];
- int main(){
- // freopen("in.txt","r",stdin);
- // freopen("out.txt","w",stdout);
- for(int i=;i<;i++)
- fac[i]=(<<i);
- while(~scanf("%s %d",str+,&m)){
- n=strlen(str+);
- m=n-m;
- rec=m;
- int k=(int)(log((double)n)/log(2.0));
- for(int i=;i<=n;i++)
- dp[i][]=i;
- for(int j=;j<=k;j++)
- for(int i=;i+fac[j]-<=n;i++){
- int pl=dp[i][j-], pr=dp[i+fac[j-]][j-];
- if(str[pl]<=str[pr])
- dp[i][j]=pl;
- else
- dp[i][j]=pr;
- }
- l=;
- tot=;
- while(m){
- r=n-m+;
- k=(int)(log((double)(r-l+))/log(2.0));
- int pl=dp[l][k], pr=dp[r-fac[k]+][k];
- if(str[pl]<=str[pr])
- p=pl;
- else
- p=pr;
- ans[tot++]=p;
- l=p+;
- m--;
- }
- int flag=;
- for(int i=;i<tot;i++){
- if(!(str[dp[ans[i]][]]-'')){
- if(flag)
- printf("%c",str[ans[i]]);
- }else{
- flag=;
- printf("%c",str[ans[i]]);
- }
- }
- if(!flag)
- printf("");
- cout<<endl;
- }
- return ;
- }
HDU_3183_A Magic Lamp的更多相关文章
- HDOJ 3183 A Magic Lamp
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3183 A Magic Lamp(RMQ)
题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...
- A Magic Lamp(贪心+链表)
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3183 A Magic Lamp RMQ ST 坐标最小值
hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...
- HDU 3183 - A Magic Lamp - [RMQ][ST算法]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...
- A Magic Lamp -- hdu -- 3183
http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 3183 A Magic Lamp(RMQ)
A Magic Lamp Time Limi ...
- hdu 3183 A Magic Lamp rmq或者暴力
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- hdu A Magic Lamp
http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- php -- PHP在linux上执行外部命令,system(),exec(),shell_exec()
目录:一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍 在PHP中调用外部命令,有三种方法: 1. 调用专门函 ...
- erlang-百度云推送Android服务端功能实现-erlang
百度云推送官方地址http://developer.baidu.com/wiki/index.php?title=docs/cplat/push 简单的介绍下原理: 百度云推送支持IOS和Androi ...
- python 模块之间相互引用
模块层级关系: ----: |->AA.py |->BB.py |->CC.py AA.py from BB import BB class AA: def sub(self, x) ...
- thinkphp 解析带html标签的内容
1.实例一 <?php echo htmlspecialchars_decode($goodsinfo['Specification']);?> 2.实例二 {$show.article| ...
- Loadrunner C 编程_1
就目前的了解.Loadrunner的脚本语言其实和C没什么区别.他内部的好多机制都是C实现的. 不过是一种“类C” 所以我从几个方面分析 1:定义常量变量和C一样 2:在LR中,C的变量和LR的参数是 ...
- 怎么让Word编辑公式又快又好
现在很多办公学习都是在电脑中进行的.很多文件论文都是在Word中编写定稿以后再打印成册或者去投稿.毫无疑问,在Word中编辑各种各样的文字与符号是一项现在社会中非常必要的技能,而这其中一项就是对公式的 ...
- 详解如何将MathType嵌入word中
将MathType嵌入word中的过程就是word插入对象的过程,插入对象是word软件中最常见的操作,MathType公式编辑器与所有的Office程序(OLE技术)都有很好的兼容性,本教程将详解如 ...
- IDE、SATA、SCSI、SAS、FC、SSD 硬盘类型
http://www.cnblogs.com/awpatp/archive/2013/01/29/2881431.html
- [mysql] Install/Remove of the Service Denied
在windos 的cmd下安装mysql 在mysql的bin目录下面执行: mysqld --install 报错: 信息如下: Install/Remove of the Service Deni ...
- makefile--嵌套执行(四)
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 在大一些的项目里面,所有源代码不会只放在同一个目录,一般各个功能模块的源代码都是分开的,各自放在 ...