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. 如何查看mysql数据库表所使用的引擎(转载)

    我们怎么样才能准确的查看mysql的存储引擎呢,下面我给大家介绍两种正确的方式. 1)正确方式一: SHOW TABLE STATUS from 数据库库名 where Name='表名' 2)mys ...

  2. python 基础数据类型 之 列表

    列表:定义 和特性 列表定义和创建: 定义:[,]内以逗号分隔,按照索引,存放各种数据类型,一般没有限制,每个位置代表一个元素 range_create = list(range(0, 10))pri ...

  3. ftp上传文件异常

    ftp一个服务器 如果是22端口 ssh-2.0-openssh_4.3 ,是什么意思? ftp服务用的是20.21端口,客户端添加ftp信息的时候输入的是21端口 ssh服务用的是22端口,应用于远 ...

  4. Windows MySQL5.7安装和配置

    http://www.leixuesong.cn/category/mysql MySQL5.7是MySQL是最新的MySQL大版本,也是官方认为目前性能最好的.MySQL5.7也有很多改动,很多新的 ...

  5. Luogu 1415-拆分数列-动态规划

    Solution 首先要找到使得最后一个数最小, 只需定义一个数组$pre[i]$ 从区间$[pre[i], i]$表示的数, 是最小的能使前面的数递增的方案. $[ pre[n], n]$即为最小的 ...

  6. Netty Reator(三)Reactor 模型

    Netty Reator(三)Reactor 模型 Netty 系列目录 (https://www.cnblogs.com/binarylei/p/10117436.html) 本文介绍 DC Sch ...

  7. Python编程笔记(第三篇)【补充】三元运算、文件处理、检测文件编码、递归、斐波那契数列、名称空间、作用域、生成器

    一.三元运算 三元运算又称三目运算,是对简单的条件语句的简写,如: 简单条件处理: if 条件成立: val = 1 else: val = 2 改成三元运算 val = 1 if 条件成立 else ...

  8. Jquery中的$.cookie()方法

    jquery.cookie中的操作: jquery.cookie.js是一个基于jquery的插件,点击下载! 创建一个会话cookie: $.cookie(‘cookieName’,'cookieV ...

  9. Ajax(6) Ajax向servlet请求数据库操作 并显示到当前页面 这个未经测试

    假设:1.你的页面在Web-Root下,内容为: <div id="showMsg"></div><input type="text&quo ...

  10. gcc -ldl 选项作用

    如果你的程序中使用dlopen.dlsym.dlclose.dlerror 显示加载动态库,需要设置链接选项 -ldl 加载动态链接库,首先为共享库分配物理内存,然后在进程对应的页表项中建立虚拟页和物 ...