A Magic Lamp

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7170    Accepted Submission(s): 2866

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

题意就是

一个序列A[1...N],一共N个数,除去M个数使剩下的数组成的整数最小。就是在A[1...N]中顺次选取N-M个数,使值最小。

直接RMQ,找l到n-m+1的最小值,然后下一个从选取的数下一个开始,因为N-M个数,所以不能过界,要不然长度不够。

不能有前导零,具体的代码里写的。

代码:

 //HDU 3183.A Magic Lamp-RMQ
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+; int n,m,h;
char c[maxn];
int a[maxn],ans[maxn];
int mi[maxn][maxn]; int Min(int x,int y)
{
return a[x]<=a[y]?x:y;
} void ST()
{
for(int i=;i<=n;i++)
mi[i][]=i;
for(int j=;(<<j)<=n;j++){
for(int i=;i+(<<j-)<=n;i++){
mi[i][j]=Min(mi[i][j-],mi[i+(<<(j-))][j-]);
}
}
} int RMQ(int l,int r)
{
int k=;
while((<<(k+))<=r-l+) k++;
int cnt=Min(mi[l][k],mi[r-(<<k)+][k]);
return cnt;
} int main()
{
while(~scanf("%s%d",c,&m)){
n=strlen(c);h=;
for(int i=;i<n;i++)
a[i+]=c[i]-'';
ST();
int l=;
m=n-m;
while(m>){
int pos=RMQ(l,n-m+);
ans[++h]=pos;
l=pos+;
m--;
}
if(h==) cout<<<<endl;
else{
int flag=;
for(int i=;i<=h;i++){
if(!flag&&a[ans[i]]==){
if(i!=h) continue;
else cout<<a[ans[i]];
}
else{
flag=;cout<<a[ans[i]];
}
}
cout<<endl;
}
}
}

HDU 3183.A Magic Lamp-区间找最小值-RMQ(ST)的更多相关文章

  1. HDU 3183 A Magic Lamp(二维RMQ)

    第一种做法是贪心做法,只要前面的数比后面的大就把他删掉,这种做法是正确的,也比较好理解,这里就不说了,我比较想说一下ST算法,RMQ的应用 主要是返回数组的下标,RMQ要改成<=(这里是个坑点, ...

  2. hdu 3183 A Magic Lamp RMQ ST 坐标最小值

    hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...

  3. hdu 3183 A Magic Lamp(RMQ)

    题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...

  4. HDU 3183 - A Magic Lamp - [RMQ][ST算法]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...

  5. hdu 3183 A Magic Lamp rmq或者暴力

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pro ...

  6. hdu 3183 A Magic Lamp 【RMQ】

    <题目链接> <转载于 >>>  > 题目大意: 给出一个长度不超过1000位的数,求删去m位数字以后形成的最小的数字是多少. 解题分析: 分析:我们可以把题 ...

  7. hdu 3183 A Magic Lamp(RMQ)

    A Magic Lamp                                                                               Time Limi ...

  8. HDU 3183 A Magic Lamp(RMQ问题, ST算法)

    原题目 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. hdu 3183 A Magic Lamp(给一个n位的数,从中删去m个数字,使得剩下的数字组成的数最小(顺序不能变),然后输出)

    1.题目大意是,给你一个1000位的数,要你删掉m个为,求结果最小数. 思路:在n个位里面删除m个位.也就是找出n-m个位组成最小数 所以在区间 [0, m]里面找最小的数.相应的下标标号i 接着找区 ...

随机推荐

  1. Java 8 Stream 用法

    一.Stream是什么 Stream 不是集合元素,它不是数据结构并不保存数据,它是有关算法和计算的,它更像一个高级版本的 Iterator.原始版本的 Iterator,用户只能显式地一个一个遍历元 ...

  2. 将new Date() 格式化为 ’2018-10-11‘ 的字符串格式

    function dateToString( date , format ){ if(!date) return ""; if (!Common.type.isDate(date) ...

  3. Eclipse自动代码补全

    Windows——>Preferences——>Java-->Editor-->Content Asist, 在Auto activation triggers for Jav ...

  4. Netty 入门初体验

    Netty简介 Netty是一款异步的事件驱动的网络应用程序框架,支持快速开发可维护的高性能的面向协议的服务器和客户端.Netty主要是对java 的 nio包进行的封装 为什么要使用 Netty 上 ...

  5. Linux下使用tree命令查看目录结构

    Linux下的文件虽然是层次型组织结构的,但是我们平时登录到主机上的时候都是使用的各种shell并没有图形界面,看上去很不直观,Linux下有个小命令叫做tree,可以以目录树的形式显示文件结构,类似 ...

  6. 强连通图(最多加入几条边使得图仍为非强连通图)G - Strongly connected HDU - 4635

    题目链接:https://cn.vjudge.net/contest/67418#problem/G 具体思路:首先用tarjan缩点,这个时候就会有很多个缩点,然后再选取一个含有点数最少,并且当前这 ...

  7. struts集合类型封装

    1.list类型封装

  8. 环境变量配错了 command not found

    一般就是忘记在PATH 前面加$ 1.可以用whereis或者which命令查看一下有没有这个命令 具体执行which lswhereis ls 2.系统环境变量导致的问题解决方案: exportPA ...

  9. PyCharm 自定义文件和代码模板

    PyCharm提供了文件和代码模板功能,可以利用此模板来快捷新建代码或文件.比如在PyCharm中新建一个html文件,新的文件并不是空的,而是会自动填充了一些基础的必备的内容,就像这样: <! ...

  10. Opencv 配置VS2012

    开始接触图像处理有一段时间了,经过前期的调研,和相关入门知识的学习,开始接触一些图像处理应用的工具.Opencv是一个图像处理的开源库,由于其开放的协议架构,国内外很多科研机构和团队都在基于openc ...