http://acm.hdu.edu.cn/showproblem.php?pid=3183

A Magic Lamp

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

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
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
using namespace std; #define N 110000
#define MOD 100000007 char s[N];
int a[N], m; int Find(int k); void Print(); void Slove(int k); int main()
{
int n; while(scanf("%s%d", s, &n)!=EOF)
{
int i, j; m=n; memset(a, , sizeof(a));
for(i=; s[i]; i++)
a[i] = s[i]-''; i=;
while()
{
int next = Find(i);
if(next== || next-i>m)
break; for(j=i; j<next; j++)
{
a[j] = -;
m--;
} i = next;
while(a[i]==) i++;
} Slove(i); Print();
}
return ;
} void Slove(int k)
{
int i, j, index, len=strlen(s)-; while()
{
if(m==) break; index=-;
for(i=k; i<=len; i++)
{
if(a[i]==-) continue;
j = i+;
while(a[j]==-) j++; if(a[i]>a[j])
{
index = i;
break;
}
}
if(index==-)
break; a[index] = -;
m--;
}
} int Find(int k)
{
int i; for(i=k+; s[i]; i++)
{
if(a[i]==)
return i;
}
return ;
} void Print()
{
int i, j, flag=; for(i=; s[i]; i++)
{
if(a[i]!= && a[i]!=-)
break;
}
for(j=i; s[j]; j++)
{
if(a[j]!=-)
{
printf("%d", a[j]);
flag = ;
}
}
if(!flag) printf(""); printf("\n");
}

A Magic Lamp -- hdu -- 3183的更多相关文章

  1. A Magic Lamp HDU - 3183 (逆向贪心/RMQ)

    Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so ...

  2. A Magic Lamp HDU - 3183(RMQ返回下标)

    原文地址:https://blog.csdn.net/acdreamers/article/details/8692384 题意: 对于一个序列A[1...N],一共N个数,除去M个数使剩下的数组成的 ...

  3. hdu 3183 A Magic Lamp(RMQ)

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

  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. hdu 3183 A Magic Lamp rmq或者暴力

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

  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 A Magic Lamp

    http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)   ...

随机推荐

  1. 关系测试# 或 print(s2-s)Python 集合

    1集合是一个无序的,不重复的数据组合,它的主要作用如下(set和dict类似,也是一组key的集合,但不存储value.由于key不能重复,所以,在set中,没有重复的key): 去重,把一个列表变成 ...

  2. Eigen解线性方程组

    一. 矩阵分解: 矩阵分解 (decomposition, factorization)是将矩阵拆解为数个矩阵的乘积,可分为三角分解.满秩分解.QR分解.Jordan分解和SVD(奇异值)分解等,常见 ...

  3. PAT 1027 打印沙漏(20)(思路)

    1027 打印沙漏(20)(20 分) 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** ***** 所谓& ...

  4. Kubernets 第一讲 初探

    1.kubernets的工作流程 (1)开始部署新的应用程序,使用kubectl客户端工具和一个准备好的包含应用程序的Deployment的yaml文件:用户通过kubectl命令将文件的内容发送给A ...

  5. JTable 查询

    public JTable query(String table) throws SQLException { DefaultTableModel tablemodel = new DefaultTa ...

  6. linux中的设备类型

    loop设备 loop设备 一.参考命令[root@localhost a]# losetup usage:  losetup loop_device                          ...

  7. linux命令行下执行循环动作

    在当前子目录下分别创建x86_64 for dir in `ls `;do (cd $dir;mkdir x86_64);done

  8. CentOS 7.0 安装配置LAMP服务器方法(Apache+PHP+MariaDB)(转)

    转自:http://www.jb51.net/os/188488.html 作者:佚名 字体:[增加 减小] 来源:osyunwei  准备篇: CentOS 7.0系统安装配置图解教程 http:/ ...

  9. 离线在MVC4中的使用

    最近在项目中用到了离线功能,自己感觉挺高端的,但是遇到了一些问题. 现在工作告一小段落,就把这次离线工作中遇到的关键技术点和难题记录下来. 什么是离线,什么时候需要离线 离线:Offline,不联网也 ...

  10. BZOJ1233 干草堆 - 单调队列优化DP

    问题描述: 若有干个干草, 分别有各自的宽度, 要求将它们按顺序摆放, 并且每层的宽度不大于 它的下面一层 ,  求最多叠几层 题解: zkw神牛证明了: 底边最短, 层数最高         证明: ...