A Magic Lamp

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2584    Accepted Submission(s): 1010

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
HDU 2009-11 Programming Contest

#include<stdio.h>
#include<string.h>
char s[1010];
int vis[1010];
int a[1010];
int main()
{
int i,j,k,l,n,m;
while(scanf("%s",s)!=EOF)
{
scanf("%d",&m);
l=strlen(s);
for(i=0;i<l;i++)
a[i]=s[i]-'0';
n=0;
int mm=m;
memset(vis,0,sizeof(vis));
while(mm--)
{
for(i=0;i<l-1;i++)
{
if(!vis[i])
{
j=i+1;
while(vis[j])
j++;
if(a[i]>a[j])
{
vis[i]=1;
n++;
break;
}
}
}
}
int kk=m-n;
for(i=l-1;i>=0;i--)
{
if(!vis[i]&&kk)
{
vis[i]=1;
kk--;
}
}
int flag=0;
int p=0;
for(i=0;i<l;i++)
{
if(!vis[i])
{
if(s[i]!='0')
flag=1;
if(flag)
{
printf("%c",s[i]);
p++;
}
}
}
if(p==0)
printf("0");
printf("\n");
}
return 0;
}

hdoj--3183--A Magic Lamp(贪心)的更多相关文章

  1. HDOJ 3183 A Magic Lamp

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

  2. hdu 3183 A Magic Lamp 贪心

    #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm& ...

  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 Limi ...

  7. HDU 3183 A Magic Lamp(RMQ问题, ST算法)

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

  8. hdu 3183 A Magic Lamp rmq或者暴力

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

  9. 【HDOJ】3183 A Magic Lamp

    RMQ. /* 3183 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MA ...

  10. HDU3183 A Magic Lamp —— 贪心(单调队列优化)/ RMQ / 线段树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题解: 方法一:贪心. 在草稿纸上试多几次可以知道,删除数字中从左到右最后一位递增(可以等于)的 ...

随机推荐

  1. SQL SERVER-约束

    NOT NULL - 指示某列不能存储 NULL 值. UNIQUE - 保证某列的每行必须有唯一的值. PRIMARY KEY - NOT NULL 和 UNIQUE 的结合.确保某列(或两个列多个 ...

  2. 使用Love2D引擎开发贪吃蛇游戏

    今天来介绍博主近期捣腾的一个小游戏[贪吃蛇],贪吃蛇这个游戏相信大家都不会感到陌生吧.今天博主将通过Love2D这款游戏引擎来为大家实现一个简单的贪吃蛇游戏,在本篇文章其中我们将会涉及到贪吃蛇的基本算 ...

  3. hdu 4628 Pieces(状态压缩+记忆化搜索)

    Pieces Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

  4. 一个软件实现的Linux看门狗—soft_wdt

    soft_wdt(下面简称本软件)是一个软件实现的Linux看门狗. 本软件是一款开源.免费软件. 下载地址: https://github.com/sunmingbao/soft-wdt/archi ...

  5. hdu 2604 Queuing (矩阵高速幂)

    Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  6. Mysql 数据迁移后 启动出错

    今天上班后不知道为什么,mysql一直无法启动,折腾了半天于是决定重装 我本地的server用的是wamp , 重装的时候, 要进行数据备份 , 我使用的最简单粗暴的备份方式, 就是直接进入到mysq ...

  7. luogu 1351 联合权值

    联合权值 题目大意 给你一个图,有\(n-1\)条边,距离均为\(1\),每距离为\(2\)的两个点的联合权值为\(W_u \times W_v\),求联合权值的最大值和联合权值总和. solutio ...

  8. MySQL日期数据类型和时间类型使用总结

    转自: http://blog.chinaunix.net/space.php?uid=11327712&do=blog&id=32416 MySQL 日期类型:日期格式.所占存储空间 ...

  9. mybatis的sql中字段两种映射(映射到实体)方式

    mybatis的xml配置文件中,字段映射的两种方式: 1.resultMap标签中将数据库的字段与实体类中的字段对应: <resultMap id="BaseResultMap&qu ...

  10. Servlet学习(九)——request

    request运行流程在Servlet学习(四)——response已介绍,不再赘述 1.通过抓包工具获取Http请求 因为request代表请求,所以我们可以通过该对象分别获得Http请求的请求行, ...