A Magic Lamp

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

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
/*
hdu3183 RMQ
给你一串数字,求出删除m个数字后的最小值,用其他方法应该很好做的
开始想的是将里面的最大值选出来,但发现并不怎么靠谱,后来参考别人思路
发现可以通过RMQ求出最小值的位置,假设要在n个数中找出m个,那么第一个数一定在
[1,n-m],找出这个数的位置x,那么第二个数则在[x+1,n-m+1]
hhh-2016-01-30 03:13:55
*/ #include <functional>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <Map>
using namespace std;
typedef long long ll;
typedef long double ld; using namespace std; const int maxn = 1005;
char str[maxn];
char ans[maxn];
int dp[maxn][20];
int mm[maxn]; int Min(int i,int j)
{
return str[i] <= str[j] ? i:j;
} void iniRMQ(int n,char c[])
{
for(int i = 0; i < n; i++)
{
dp[i][0] = i;
}
for(int j = 1; j <= mm[n]; j++)
{
for(int i = 0; i+(1<<j)-1 < n; i++)
dp[i][j] = Min(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
}
} int RMQ(int x,int y)
{
int k = mm[y-x+1];
return Min(dp[x][k],dp[y-(1<<k)+1][k]);
} int main()
{
int m;
mm[0] = -1;
for(int i = 1;i <= 1000;i++)
mm[i] = ((i&(i-1)) == 0)? mm[i-1]+1:mm[i-1];
while(scanf("%s%d",str,&m) != EOF)
{
int n = strlen(str);
iniRMQ(n,str);
int now,tot;
now = tot = 0;
m = n-m;
while(m--)
{
now = RMQ(now,n-m-1);
ans[tot++] = str[now++];
}
for(now = 0; now < tot; now++)
if(ans[now] != '0')
break; if(now == tot)
printf("0\n");
else
{
while(now < tot)
{
printf("%c",ans[now]);
now ++;
}
printf("\n");
}
}
return 0;
}

  

hdu3183 RMQ的更多相关文章

  1. hdu3183 rmq求区间最值的下标

    两个月前做的题,以后可以看看,是rmq关于求区间最值的下标 /* hdu3183 终点 给一个整数,可以删除m位,留下的数字形成一个新的整数 rmq 取n-m个数,使形成的数最小 */ #includ ...

  2. HDU3183 RMQ/贪心

    A Magic Lamp Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately ...

  3. HDU3183 A Magic Lamp —— 贪心(单调队列优化)/ RMQ / 线段树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题解: 方法一:贪心. 在草稿纸上试多几次可以知道,删除数字中从左到右最后一位递增(可以等于)的 ...

  4. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  5. UVA 11235Frequent values(RMQ)

    训练指南P198 题意:给出一个非降序排列的整数数组a1, a2…… an,你的任务是对于一系列询问(i,j),回答ai, ai+1 ……aj 中出现的次数最多的次数 这题不仅学到了rmq的应用还学到 ...

  6. 51nod1174(RMQ)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1174 题意:中文题诶- 思路:RMQ模板题 关于RMQ: h ...

  7. 2016 ACM/ICPC Asia Regional Dalian Online 1008 Function 二分+RMQ

    Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submissio ...

  8. Gym 100646 F Tanks a Lot RMQ

    Problem F: Tanks a Lot Imagine you have a car with a very large gas tank - large enough to hold what ...

  9. (RMQ版)LCA注意要点

    inline int lca(int x,int y){ if(x>y) swap(x,y); ]][x]]<h[rmq[log[y-x+]][y-near[y-x+]+]])? rmq[ ...

随机推荐

  1. openlayers调用瓦片地图分析

    网上有诸多资料介绍openlayers如何调用百度地图或者是天地图等常见互联网地图,本文作者使用的是不是常见的互联网瓦片,现将调用过程进行整理与大家分享. 首先,openlayers就不赘述了(官网: ...

  2. java 零基础搭建dubbo运行环境

    一:简介    以前做项目时,分布式环境都是其它同事在搭建,自己也没参与分布式环境搭建,只负责开发,由于近段时间工作重心转到android,java后台有一段时间没有接触了,刚好这几天有空,决定自己动 ...

  3. WebBench的安装与使用

    webbench最多可以模拟3万个并发连接去测试网站的负载能力. 一.编译安装 1.上传压缩包到虚机里,rz webbench-1.5.tar.gz 2.解压 tar zxvf webbench-1. ...

  4. 推荐几个IDEA插件,Java开发者撸码利器。

    这里只是推荐一下好用的插件,具体的使用方法不一一详细介绍. JRebel for IntelliJ 一款热部署插件,只要不是修改了项目的配置文件,用它都可以实现热部署.收费的,破解比较麻烦.不过功能确 ...

  5. MySQL基础操/下

    MySQL基础操 一.自增补充 desc (表名)t1: 查看表格信息内容 表的信息 show create table t1(表名):也是查看信息,还不多是横向查看 show create tabl ...

  6. ehcache.xml 属性大全

    属性大全 name:缓存名称. maxElementsInMemory:缓存最大个数. eternal:对象是否永久有效,一但设置了,timeout将不起作用. timeToIdleSeconds:设 ...

  7. Java基础语法<十> Jar文件

    1 JAR文件            java归档文件,压缩的            jdk/bin jar工具制作jar文件              jar程序选项 1.1清单文件         ...

  8. urllib.request.Request

    import urllib.request #可以将url先构造成一个Request对象,传进urlopen #Request存在的意义是便于在请求的时候传入一些信息,而urlopen则不 reque ...

  9. 使用javaMail实现简单邮件发送

    一.首先你要用来发送邮件的qq邮箱需要开通pop3/smtp服务,这个可以百度一下就知道了 二.导入所需要的jar包,我使用的是maven添加依赖 <dependency> <gro ...

  10. java中的内部类概念

    内部类和外部类可以互相访问私有属性 1.普通内部类实例化方式 外部类.内部类 对象 = new 外部类().new 内部类(); class Outer{//外部类 private String ms ...