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. 为什么说windows会死机,Linux不会死机

    通常所说的死机是指操作没有响应了,但是操作系统的核心仍然在工作.在windows中,由于只有一个界面,没有响应就是死机了:而在Linux中可有tty1-tty7,死了一个开另外一个把死了的那个杀掉就可 ...

  2. Java并发-多线程面试(全面)

    1. 什么是线程?2. 什么是线程安全和线程不安全?3. 什么是自旋锁?4. 什么是Java内存模型?5. 什么是CAS?6. 什么是乐观锁和悲观锁?7. 什么是AQS?8. 什么是原子操作?在Jav ...

  3. C# devexpress gridcontrol 分页 控件制作

    这个小小的功能实现起来还是有一点点复杂, 分页单独一个usercontrol 出来,导致查询换页 与gridcontrol页面分离,  一般通过换页事件通知girdcontrol 做出查询 查询来说有 ...

  4. 分析入口文件main.php

    在分析之前,需要了解php cli模式下的编程 1.了解getopt函数,php手册地址:http://php.net/manual/zh/function.getopt.php static pri ...

  5. PHP 异步使用swoole的可行性测试

    PHP的异步.并行.高性能网络通信引擎swoole框架,在一开始我就比较注意,原因无他,php在swoole未出的情况下在多线程调度上确实算得上没有较好的解决方案. 我以系统的注册流程举例,在比较复杂 ...

  6. linux 使用笔记3

    解决linux下打开txt乱码问题 在Linux下要阅读windows生成的txt文件,需要通过iconv进行字符转化 iconv -f gb2312 -t utf8 ./读书笔记.txt > ...

  7. 转录本组装软件StringTie的使用说明

    转录本组装软件StringTie的使用说明 StringTie 转录本组装软件StringTie的使用说明 转录组分析流程 HISTA + StringTie 组合.其Protocol 发表在Natu ...

  8. anaconda的源配置的坑

    anaconda是一个python的科学计算的包集合,它提供了一个非常好用的包管理器 conda,类似于pip. 为了速度(不仅为了速度,没有清华源你就被墙了,速度为0),我们使用清华源: 在类uni ...

  9. jQuery Autocomplete 备忘录

    之前使用过此 widget,如今再次需要,发现很多东西已经记不起来了,当然之前用的版本也不一样. 使用之前当然是先认真阅读官方的说明文档和示例,这点很重要,而不是东一块西一点的去网上瞎找资料.Opti ...

  10. OneZero第三周第三次站立会议(2016.4.6)

    1. 时间: 13:05--13:15  共计10分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...