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. 记js的一个奇葩问题!!!!!!!!!!!!

    <a id='gc-yl' onclick='Preview('" + imgPath + "')' style='margin-left:5px;' >预览</ ...

  2. Java 基本概念:jvm、jdk、jre、jse

    jvm 是java虚拟机,将java的class字节码文件翻译成二进制可执行程序.jdk 是java的开发包 Javasdk, java的开发工具,包含SUN公司提供的javaAPI,将java源码编 ...

  3. php中ignore_user_abort函数的用法(定时)

    PHP中的ignore_user_abort函数是当用户关掉终端后脚本不停止仍然在执行,可以用它来实现计划任务与持续进程,下面会通过实例讨论ignore_user_abort()函数的作用与用法. i ...

  4. Android ContentProvider、ContentResolver和ContentObserver的使用

    1.ContentProvider.ContentResolver和ContentObserver ContentProvider是Android的四大组件之中的一个,可见它在Android中的作用非 ...

  5. AOPR密码过滤器

    在Advanced Office Password Recovery任一攻击的破解选项设置窗口都有一个“编辑密码过滤器”按钮,设置好AOPR密码破解工具的密码过滤器可以大大提高破解速度,下文将具体介绍 ...

  6. 面试题:谈谈如何优化MYSQL数据库查询

    1.优化数据类型 MySQL中数据类型有多种,如果你是一名DBA,正在按照优化的原则对数据类型进行严格的检查,但开发人员可能会选择他们认为最简单的方案,以加快编码速度,或者选择最明显的选择,因此,你可 ...

  7. 第四章 Spring.Net 如何管理您的类___对象的作用域

    Spring.Net 中对象的作用域,就是描述对象的部署模式 ,Spring.Net 中对象可以通过两种模式布署: ① singleton(单例模式) ② 非singleton 也叫非单例模式(或者叫 ...

  8. MySQL性能优化(十)-- 主从复制(一主多从)

    环境准备: Linux1(matser) Linux2(slave) Linux3(slave) 搭建 1.先清空原来的master和slave配置 reset master; 2.

  9. Python 数据类型:字符串

    一.字符串介绍 字符串是由单引号/双引号/三引号引起来的,由字母 .数字或符号等构成的一串字符 In [1]: name = "Tom" # 定义字符串 In [2]: type( ...

  10. Core Location和MapKit的一些简单使用

      Core Location 1. 基本对象是CLLocation,有属性coordinate, altitude, horizontal/vertical Accuracy, timestamp, ...