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. php通过字符串生存hashCode

    /** * * 生存hashCode * */function hashCode($str){ if(empty($str)) return ''; $str = strtoupper($str); ...

  2. [转]ASP.NET MVC 5 - 给电影表和模型添加新字段

    在本节中,您将使用Entity Framework Code First来实现模型类上的操作.从而使得这些操作和变更,可以应用到数据库中. 默认情况下,就像您在之前的教程中所作的那样,使用 Entit ...

  3. 超全面的JavaWeb笔记day11<JSP&Session&Cookie&HttpSession>

    1.JSP 2.回话跟踪技术 3.Cookie 4.HttpSession JSP入门 1 JSP概述 1.1 什么是JSP JSP(Java Server Pages)是JavaWeb服务器端的动态 ...

  4. Windows7 64bits下安装TensorFlow CPU版本(图文详解)

    不多说,直接上干货! Installing TensorFlow on Windows的官网 https://www.tensorflow.org/install/install_windows 首先 ...

  5. linux下更改vncserver的密码

    Linux下VNC配置多个桌面和修改密码 1:vncserver2:iptables -I INPUT -p tcp --dport 5901 -j ACCEPT   客户端方式3:iptables ...

  6. Dubbo注册中心Zookeeper安装步骤

    第一步:安装jdk 第二步:上传zookeeper至Linux 第三步:解压zookeeper安装包(/soft目录是我在根目录下建立的一个用户存放上传安装包的目录),解压命令tar -xvf /so ...

  7. C++成员初始化列表的语法

    如果Classy是一个累,而mem1.mem2.mem3都是这个类的数据称源,则类构造函数可以使用如下的语法来初始化数据成员:Classy::Classy(int n, int m) : mem1(n ...

  8. 优秀的PHP开发者是怎样炼成的?

    4.在数据库中避免使用联合操作 比起其它的Web编程语言来说,PHP的数据库功能十分强大.但是在PHP中数据库的运行仍然是一件十分费时费力的事情,所以,作为一个Web程序员,要尽量减少数据库的查询操作 ...

  9. 时序数据库技术体系 – InfluxDB 多维查询之倒排索引

    本文转自: http://hbasefly.com/2018/02/09/timeseries-database-5/ 在时序数据库概述一文中,笔者提到时序数据库的基础技术栈主要包括高吞吐写入实现.数 ...

  10. 图片asp木马的制作方法[转]

    一个网站里面除了asp文件,再就数图片文件最多了,它让我们的网页"美丽动人"嘻嘻,但是你有没有想到过这里面暗藏的杀机,图片也可以是asp木马. 一个网站里面除了asp文件,再就数图 ...