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. Vue 进度条 和 图片的动态更改

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. python sockerserver tcp 文件下载 udp

    #tcp serverclass MyHandler(socketserver.BaseRequestHandler): def handle(self): # 通信循环 while True: tr ...

  3. python 3.6.5 sys模块和os模块

    1 sys.argv 命令行参数List,第一个元素是程序本身路径 2 sys.exit(n) 退出程序,正常退出时exit(0) 3 sys.version 获取Python解释程序的版本信息 4 ...

  4. React-router4 第三篇 BasicURL ParametersRedirects (Auth) 谷歌翻译:重定向

    依旧是地址 https://reacttraining.com/react-router/web/example/auth-workflow 上来一步走 先导入模块 import React, { P ...

  5. jenkins配置slave节点 windows

    1.在slave机器上,访问已安装的jenkins站点,如图,选择新建节点 配置节点 2.打开新建节点,如图,点击launch按钮下载slave-agent.jnlp文件,点击slave.jar下载该 ...

  6. PAT 1036 跟奥巴马一起编程(15)(代码)

    1036 跟奥巴马一起编程(15)(15 分) 美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014年底,为庆祝"计算机科学教育周& ...

  7. 图片延时加载原理 和 使用jquery实现的一个图片延迟加载插件(含图片延迟加载原理)

    图片加载技术分为:图片预加载和图片延时加载. javascript图片预加载和延时加载的区别主要体现在图片传输到客户端的时机上,都是为了提升用户体验的,延时加载又叫懒加载.两种技术的本质:两者的行为是 ...

  8. 如何使用NSDL玩转微信跳一跳

    目前网上介绍windows和IOS操作系统上玩微信跳一跳的有很多文章,但介绍Linux平台下的文章相对较少,所以动手操作下和大家分享,同时感谢wangshub在github上的分享: 1 下载wech ...

  9. button获取验证码60秒倒计时 直接用

    __block ; __block UIButton *verifybutton = _GetverificationBtn; verifybutton.enabled = NO; dispatch_ ...

  10. ubuntu下安装配置ADB

    1.下载SDK Tools for Linux,地址:http://developer.android.com/sdk/index.html 2.解压,将 android-sdk-linux 文件夹放 ...