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

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
 
  • 长度为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的更多相关文章

  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)   ...

随机推荐

  1. windows 解压缩命令

    首先安装winrar 压缩: 命令:start winrar a test test.py 解压: 命令:start winrar x -y test.rar F:\batShell\test\tes ...

  2. (转)I 帧和 IDR 帧的区别

    I 帧和 IDR 帧的区别:http://blog.csdn.net/skygray/article/details/6223358 IDR 帧属于 I 帧.解码器收到 IDR frame  时,将所 ...

  3. 使用Ultra Librarian转换芯片的Altium Designer封装格式

    第一步:找到对应芯片的CAD文件,以OPA350为例: http://www.ti.com/product/opa350   RE: 使用Ultra Librarian转换TI芯片的Altium De ...

  4. PL/SQL中decode函数简介

    今天看别人的SQL时看这里面还有decode()函数,以前从来没接触到,上网查了一下,还挺好用的一个函数,写下来希望对朋友们有帮助哈! decode()函数简介: 主要作用:将查询结果翻译成其他值(即 ...

  5. 第五章 使用 SqlSession(MyBatis)

    在 MyBatis 中,你可以使用 SqlSessionFactory 来创建 SqlSession.一旦你获得一个 session 之后,你可以使用它来执行映射语句,提交或回滚连接,最后,当不再需要 ...

  6. Unity3d + PureMVC框架搭建

    0.流程:LoginView-SendNotification()---->LoginCommand--Execute()--->调用proxy中的函数操作模型数据--LoginProxy ...

  7. Spring------SpringBoot中注解

    转载: http://www.tuicool.com/articles/bQnMra

  8. java中Double的isInfinite()和isNaN()

    在Double和Float类中都有这两个方法,用于判断是否是无穷大及是否为非数字 public boolean isInfinite()如果此对象表示的值是正无穷大或负无穷大,则返回 true:否则返 ...

  9. /etc/hosts

    /etc/hosts 是 Linux 系统中一个负责IP地址与域名快速解析的文件,解析优先级:DNS缓存 > hosts > DNS服务(/etc/resolv.conf) 文件格式:网络 ...

  10. INSTALL_FAILED_INVALID_APK

    在项目中无意中把APP只写成了 xxx  没有xxx.xxx.xxx  掉坑里了,找了好久,给大家提不醒