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. <history> 特别报道:Google离职富翁们都在干什么?

    特别报道:Google离职富翁们都在干什么? 时间:2008-01-23 10:16:47作者:CNET科技资讯网 本文关键词:Google CNET科技资讯网1月23日国际报道 假如你拥有1千万或1 ...

  2. TouchSlide 插件使用介绍

    TouchSlide(PC端插件http://www.superslide2.com/demo.html#effect1) 可用于javascript触屏滑动特效插件,移动端滑动特效,触屏焦点图,触屏 ...

  3. python 3.6.5 map() max() lambda匿名函数

    python 3.6.5 sample: map() 会根据提供的函数对指定序列做映射. 第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 functi ...

  4. hdu 5459(2015沈阳网赛) Jesus Is Here

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果 ...

  5. git的命令详解

    # git三个区 + 工作区: 写代码的地方 + 暂存区: 暂时存储代码 + 仓库区: 代码提交到了仓库区,就生成一条历史记录(版本) 工作区===> 暂存区 ===> 仓库区 # git ...

  6. 20172306《java程序设计与数据结构》第六周学习总结

    20172306<Java程序设计>第六周学习总结 教材学习内容总结 第八章关键学习了数组的相关内容.我觉得主要分一下几点: 1.索引是从0开始,要区分好索引值和个数值.0的索引处是第一个 ...

  7. Python pip下载安装库 临时用清华镜像命令

    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple C:\Users\mu\pip 新建pip.ini [global] index-url ...

  8. macOS X Mount NFS Share / Set an NFS Client

    last updated November 3, 2018 in CategoriesLinux, Mac OS X, UNIX How do I access my enterprise NAS s ...

  9. InputMethodManagerService处理输入法——监听APK变动

    android\frameworks\base\services\java\com\android\server\InputMethodManagerService.java public Input ...

  10. Linux学习笔记:Shell脚本学习

    概念 真正能够控制计算机硬件(CPU.内存.显示器等)的只有操作系统内核(Kernel),图形界面和命令行只是架设在用户和内核之间的一座桥梁. 由于安全.复杂.繁琐等原因,用户不能直接接触内核(也没有 ...