hdu3183 RMQ
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
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?
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.
If the result contains leading zero, ignore it.
1000001 1
100001 2
12345 2
54321 2
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的更多相关文章
- hdu3183 rmq求区间最值的下标
两个月前做的题,以后可以看看,是rmq关于求区间最值的下标 /* hdu3183 终点 给一个整数,可以删除m位,留下的数字形成一个新的整数 rmq 取n-m个数,使形成的数最小 */ #includ ...
- HDU3183 RMQ/贪心
A Magic Lamp Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately ...
- HDU3183 A Magic Lamp —— 贪心(单调队列优化)/ RMQ / 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题解: 方法一:贪心. 在草稿纸上试多几次可以知道,删除数字中从左到右最后一位递增(可以等于)的 ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- UVA 11235Frequent values(RMQ)
训练指南P198 题意:给出一个非降序排列的整数数组a1, a2…… an,你的任务是对于一系列询问(i,j),回答ai, ai+1 ……aj 中出现的次数最多的次数 这题不仅学到了rmq的应用还学到 ...
- 51nod1174(RMQ)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1174 题意:中文题诶- 思路:RMQ模板题 关于RMQ: h ...
- 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 ...
- 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 ...
- (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[ ...
随机推荐
- HTML5的新的结构元素介绍
HTML5的新的结构元素介绍 一.HTML5与HTML4的区别 1. 取消了一些过时的HTML4的标签 其中包括纯粹显示效果的标记,如<font>和<center>,它们已经被 ...
- NetFPGA-1G-CML从零开始环境配置
NetFPGA-1G-CML从零开始环境配置 前言 偶得一块NetFPGA-1G-CML,跟着github对NetFPGA-1G-CML的入门指南,一步步把配置环境终于搭建起来,下面重新复现一下此过程 ...
- JFinal项目发送邮件——jfinal-mail-plugin
JFianl框架: JFinal 是基于 Java 语言的极速 WEB + ORM 框架,其核心设计目标是开发迅速.代码量少.学习简单.功能强大.轻量级.易扩展.Restful.在拥有Java语言所有 ...
- iis / asp.net 使用 .config 和 .xml 文件的区别
由于在项目中有同学使用后缀为 .xml 的文件作为配置文件,而配置文件中有一些敏感信息被记录,如接口地址,Token,甚至还有数据库连接字符串. 以前都没想过为何微软会使用.config 的后缀在作为 ...
- Win7添加php环境变量.
1) "我的电脑"右键"属性"->高级系统设置->环境变量->系统变量->Path->编辑 2) 将PHP的执行路径的目录&quo ...
- ArrayList、Vector、LinkedList、HashMap、HashTable的存储性能和特性
ArrayList和Vector都是使用数组方式存储数据,次数组元素大于实际存储的数据以便添加和插入元素,它们都允许直接按序号索引元素,但是插入元素要涉及数组元素移动等内存操作,所以索引数据快而插入数 ...
- JSON(四)——异步请求中前后端使用Json格式的数据进行交互
json格式的数据广泛应用于异步请求中前后端的数据交互,本文主要介绍几种使用场景和使用方法. 一,json格式字符串 <input type="button" id=&quo ...
- golang-在gin中cookie跨域设置(配合ajax)
1.当我在golang中,在前后端分离的情况下使用cookies时发现,跨域没有被允许.代码如下: func AccessJsMiddleware() gin.HandlerFunc { return ...
- python——re模块
python--re模块 一 正则表达式的作用 1.给字符串进行模糊匹配, 2.对象就是字符串 二 字符匹配(普通字符.元字符) 普通字符:数字字符和英文字母和自身匹配 2.元字符:. ^ $ * + ...
- python——常用模块2
python--常用模块2 1 logging模块 1.1 函数式简单配置 import logging logging.debug("debug message") loggin ...