HDU_3183_A Magic Lamp
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
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
- 长度为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的更多相关文章
- HDOJ 3183 A Magic Lamp
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3183 A Magic Lamp(RMQ)
题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...
- A Magic Lamp(贪心+链表)
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3183 A Magic Lamp RMQ ST 坐标最小值
hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...
- HDU 3183 - A Magic Lamp - [RMQ][ST算法]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...
- A Magic Lamp -- hdu -- 3183
http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 3183 A Magic Lamp(RMQ)
A Magic Lamp Time Limi ...
- hdu 3183 A Magic Lamp rmq或者暴力
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- hdu A Magic Lamp
http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 从零开始,制定PHP学习计划
7月份学习计划1-15 搭建开发环境.做个小demo 增删改查.Mysql数据库16-30号 架构设计.服务器管理.版本控制 8月份正式入手项目jquery脚本学习Thinksns开源学习.核心业务学 ...
- ffmpeg avformat_open_input返回失败的解决办法
用ffmpeg做的第一个程序,参考网上的代码,就出现了一些问题,其中avformat_open_input返回失败. 下面是我在网上收集到的失败信息的相关解决: /////////////////// ...
- react新手入门(序)
之前在软件园使用的是react,当时为了做个集光推送,自己去搭过react,这次项目中继续使用react,于是又重新操作了遍,恰巧公司买了本react的书籍,这本书写的非常好,看着并不觉得拗口,很容易 ...
- C#获取并修改文件扩展名的方法
本文实例讲述了C#获取并修改文件扩展名的方法.分享给大家供大家参考.具体分析如下: 这里使用C#编程的方法改变文件扩展名的文件,必须使用Path类. Path类用来解析文件系统路径的各个部分.静态方法 ...
- nginx+tomcat实现负载均衡以及session共享(linux centos7环境)
一.nginx的安装 1.准备三份tomcat tomcat1 设置端口 8080 tomcat2 设置端口 8081 tomcat3 设置端口 8082 2. 下载nginx 3. 解压到/home ...
- java web接口controller测试控制台输出乱码
接口上配置:
- 如何让View一直沿z轴旋转
#import <QuartzCore/QuartzCore.h>... CABasicAnimation *rotationAni = [CABasicAnimation animati ...
- Linux 权限修改
chown -R 用户名:组名 文件夹名chown -R xu:hadoop hadoop 将hadoop目录(以及其下的所有子目录/文件)的属主用户设为xu, xu 的组名为group
- 无法查找或打开 PDB 文件
emmmmmmmmmmmmm...建议:不用管!!! 参考: 在 Visual Studio 调试器中指定符号 (.pdb) 和源文件 https://msdn.microsoft.com/zh-cn ...
- 【SSH进阶之路】Hibernate映射——一对一双向关联映射(六)
上篇博文[SSH进阶之路]Hibernate映射--一对一单向关联映射(五),我们介绍了一对一的单向关联映射,单向是指仅仅能从人(Person)这端载入身份证端(IdCard),可是反过来.不能从身份 ...