hdoj--3183--A Magic Lamp(贪心)
A Magic Lamp
Total Submission(s): 2584 Accepted Submission(s): 1010
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?
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.
If the result contains leading zero, ignore it.
178543 4
1000001 1
100001 2
12345 2
54321 2
13
1
0
123
321
#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(贪心)的更多相关文章
- HDOJ 3183 A Magic Lamp
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3183 A Magic Lamp 贪心
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm& ...
- hdu 3183 A Magic Lamp(RMQ)
题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...
- hdu 3183 A Magic Lamp RMQ ST 坐标最小值
hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...
- HDU 3183 - A Magic Lamp - [RMQ][ST算法]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...
- hdu 3183 A Magic Lamp(RMQ)
A Magic Lamp Time Limi ...
- HDU 3183 A Magic Lamp(RMQ问题, ST算法)
原题目 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3183 A Magic Lamp rmq或者暴力
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 【HDOJ】3183 A Magic Lamp
RMQ. /* 3183 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MA ...
- HDU3183 A Magic Lamp —— 贪心(单调队列优化)/ RMQ / 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题解: 方法一:贪心. 在草稿纸上试多几次可以知道,删除数字中从左到右最后一位递增(可以等于)的 ...
随机推荐
- 在Html5中与服务器交互
转自原文 在Html5中与服务器交互 刚刚涉足职场,上头就要我研究HTML5,内嵌到手机上,这对我来说完全是一个陌生的领域,不过也正好给自己一个机会来学习,最近做到要跟服务器交互这部分,这部分可是卡了 ...
- [ReactVR] Animate Text, Images, Views, and 3D Elements Using the Animated Library in React VR
Motion is an important aspect of a complete immersive experience, therefor we are going to look into ...
- MVC传递数据-传递对象或对象集合
前言 本文主要介绍从View(或者js)文件向Controller提交对象或者对象集合.比方.将表格中的一行数据作为一个对象提交.或将多行数据作为一个集合提交到Controller. 回想 从View ...
- iOS 图像处理-调整图像亮度
- (UIImage*) getBrighterImage:(UIImage *)originalImage { UIImage *brighterImage; CIContext *context ...
- HDU 4415 Assassin's Creed(贪心)
pid=4415">HDU 4415 题意: 壮哉我Assassin! E叔有一柄耐久度为m的袖剑,以及n个目标士兵要去解决. 每解决掉一个士兵,消耗袖剑Ai的耐久度.且获得该士兵的武 ...
- I hate it (线段树)
B - I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- android drawable资源调用使用心得
1. 调用顺序 android 调用应用图片资源时,会优先选择当前手机屏幕dpi对应的的文件夹(如drawable-ldpi, drawable-mdpi, drawable-hdpi, drawab ...
- javascript系列-class5.数组
转载请标明出处! 栈堆结构: 堆栈都是一种数据项按序排列的数据结构,只能在一端(称为栈顶(top))对数据项进行插入和删除. 栈:存放的是路径:容量有限(在一开始被定义之后就不会改变了): ...
- 90.bower解决js的依赖管理
转自:https://blog.csdn.net/u011537073/article/details/52951122 前言一个新的web项目开始,我们总是很自然地去下载需要用到的js类库文件,比如 ...
- validation-api参数校验
这里针对springboot项目结构 maven添加: <dependency> <groupId>javax.validation</groupId> <a ...